nginx 配置 proxy_pass時可以實現URL路徑的部分替換。
1.proxy_pass的目標地址,默認不帶/,表示只代理域名,url和querystring部分不會變(把請求的path拼接到proxy_pass目標域名之后作為代理的URL)
2.如果在目標地址后增加/,則表示把path中location匹配成功的部分剪切掉之后再拼接到proxy_pass目標地址
例子:
server {
location /abc {
proxy_pass http://server_url;
}
location /abc {
proxy_pass http://server_url/;
}
}
比如請求 /abc/b.html
如上兩個匹配成功后,實際代理的目標url分別是
http://server_url/abc/b.html (把/abc/b.html拼接到http://server_url之后)
http://server_url/b.html (把/abc/b.html的/abc去掉之后,拼接到http://server_url/之后)