在nginx中,是否可以代理将根目录传递到一个地址,将其余地址传递到另一个地址?

在nginx中,是否可以代理将根目录传递到一个地址,将其余地址传递到另一个地址?,nginx,proxy,Nginx,Proxy,我的nginx配置中有这个代理过程 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-C

我的nginx配置中有这个代理过程

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';
}
}

我想代理\u传递/content到$address1,但我想代理\u传递任何其他/content/something到$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

我想代理\u传递/content到$address1,但我想代理\u传递任何其他/content/something到$address2在nginx中这可能吗


对。您可以使用location=/content w/$address1和location/content w/$address2;这将是首选配置,尤其是当两个地址没有共享那么多时。

如果我的答案回答了这个问题,您能+1吗?如果没有,请告诉我缺少什么。谢谢