我有我的nginxconfiguration这个代理传递。
location /content { proxy_set_header Host $proxy_host; proxy_pass $address1; if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204; } if ($request_method = 'POST') { add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; } if ($request_method = 'GET') { add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; }
}
我想proxy_pass /content到$address1但我想proxy_pass任何其他/content/something_else $address2这是可能的nginx?
例如,如果我点击http://www.example.com/content?some_other_param=value它将被转发到http://www.content.com但如果我点击http://www.example.com/content/article?some_param=value会击中http://www.different_content.com
我想proxy_pass
/content到$address1但我想proxy_pass任何其他/content/something_else$address2这是可能的nginx?
是。 你可以使用location = /content w / $address1和location /content w / $address2 ; 这将是首选的configuration,特别是如果两个地址不共享那么多。
您需要添加第二个块,如:
location ~ ^/content/.+$ { proxy_set_header Host $proxy_host; proxy_pass $address2; .... }
如果请求匹配正则expression式,nginx将使用这个块,也就是说,如果请求以/content/开始。