我尝试使用if,location 处理部分URL,然后放行到 proxy_pass 反复尝试都提示下面的错误
Nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression,or inside named location,or inside "if" statement,or inside "limit_except" block in /etc/Nginx/conf.d/info.mydomain.com.conf:112?
Nginx: configuration file /etc/Nginx/Nginx.conf test Failed
最后发现使用$request_uri变量可以解决上述问题.
if ( $request_uri ~ "^/\w+\.xml$") {
proxy_pass http://www.mydomain.com/xml$request_uri;
break;
}
if ( $request_uri ~ "^/public/datas/\w+\.xml$") {
proxy_pass http://www.mydomain.com/$request_uri;
break;
}