nginx 反向代理 proxy_pass詳解


在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后面是沒有/的

 


免責聲明!

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



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