Dictionary NGINX中useragent的不同文件

Dictionary NGINX中useragent的不同文件,dictionary,nginx,user-agent,Dictionary,Nginx,User Agent,如何正确编写nginx服务器的配置 ... if the client has useragent (A) and it refers to http://somehost.domain/somefile.someextension nginx responding a file from the root /file.zip if the client has useragent (B) and it refers to http://somehost.domain/somefi

如何正确编写nginx服务器的配置

...
if the client has useragent (A) and it refers to http://somehost.domain/somefile.someextension
       nginx responding a file from the root /file.zip
if the client has useragent (B) and it refers to http://somehost.domain/somefile.someextension
       nginx responding a file from the root /file2.zip
if the client has useragent (C) and it refers to http://somehost.domain/somefile.someextension
       nginx responding 403 error
...

我做了以下代码:

map $http_user_agent $browser {
        "~*Firefox"             "/var/www/test1";
        "~*Wget"                "/var/www/test2";
        "~*SomeUserAgent"       "/var/www/test3";
}

server {
...
root $browser

但是如何获得传递到任何地址的条件?

您可以使用
映射
位置
别名
指令根据头的值将特定URI映射到多个文件

例如(所有文件都在同一目录中):

仅需要
if
块将404响应更改为403响应

更多信息,请参阅

map $http_user_agent $browser {
    default           "nonexistent";
    "~*Firefox"       "file.zip";
    "~*Wget"          "file1.zip";
}

server {
    ...
    location = /somefile.someextension {
        alias /path/to/directory/$browser;

        if (!-f $request_filename) {
            return 403;
        }
    }
}