2017-08-04 86 views
0

我在我的nginx配置中有这个代理传递。我可以通过代理传递根到一个地址,其余的地址在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'; 
} 

}

我想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

+0

如果我的答案回答了问题,可以请+1吗?如果没有,请告诉我缺少什么。谢谢。 – cnst

回答

1

我想proxy_pass /content$address1但我想proxy_pass任何其他/content/something_else$address2这在nginx中可能吗?

是的。您可以使用location = /content w/$address1location /content w/$address2;这将是首选配置,特别是如果这两个地址不能共享那么多。

+0

非常感谢。我会尝试的。 – toy