在nginx配置文件中進行代理轉發時,如果在proxy_pass後面的url加/,代表絕對路徑,替換被代理路徑;如果不加,代表相對路徑,將匹配到的url路徑追加到代理路徑;
eg:
所有實例都調用請求http://www.test.com/test/aaa.html
第一種:
location /test/ {
proxy_pass http://127.0.0.1:8080
}
結論:http://www.test.com/test/aaa.html 代理爲 http://127.0.0.1:8080/test/aaa.html
第二種:相比第一種代理服務多了/
location /test/ {
proxy_pass http://127.0.0.1:8080/
}
結論:http://www.test.com/test/aaa.html 代理爲 http://127.0.0.1:8080/aaa.html
第三種:相比第二種代理服務多了/demo
location /test/ {
proxy_pass http://127.0.0.1:8080/demo
}
結論:http://www.test.com/test/aaa.html 代理爲 http://127.0.0.1:8080/demoaaa.html
第四種:相比第三種代理服務多了最後一個/
location /test/ {
proxy_pass http://127.0.0.1:8080/demo/
}
結論:http://www.test.com/test/aaa.html 代理爲 http://127.0.0.1:8080/demo/aaa.html