Nginx location 配置 后路徑映射問題 (路徑替換)


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/之后)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM