proxy_pass與正則表達式
我嘗試使用if , location 處理部分URL, 然後放行到 proxy_pass 反復嘗試都提示下面的錯誤 www.2cto.com
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變量可以解決上述問題. www.2cto.com
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;
}