本文為joshua317原創文章,轉載請注明:轉載自joshua317博客 https://www.joshua317.com/article/179
在nginx中配置proxy_pass代理轉發時,如果在proxy_pass后面的url加/,表示絕對根路徑;如果沒有/,表示相對路徑,把匹配的路徑部分也給代理走。
假設下面四種情況分別用 http://192.168.1.1/proxy/test.html
進行訪問。
第一種情況,代理到URL:http://192.168.4.173:8084/test.html
location /proxy/ {
proxy_pass http://192.168.4.173:8084/;
}
注意:proxy
后面以及 192.168.4.173:8084
后面都有/
第二種(相對於第一種,最后少一個 / ),代理到URL:http://192.168.4.173:8084/proxy/test.html
location /proxy/ {
proxy_pass http://192.168.4.173:8084;
}
注意:192.168.4.173:8084
后面是沒有/的
第三種,代理到URL:http://192.168.4.173:8084/gateway/test.html
location /proxy/ {
proxy_pass http://192.168.4.173:8084/gateway/;
}
注意:192.168.4.173:8084/gateway
后面是有/的
第四種(相對於第三種,最后少一個 / ),代理到URL:http://192.168.4.173:8084/gatewaytest.html
location /proxy/ {
proxy_pass http://192.168.4.173:8084/gateway;
}
注意:192.168.4.173:8084/gateway
后面是沒有/的
本文為joshua317原創文章,轉載請注明:轉載自joshua317博客 https://www.joshua317.com/article/179