nginx proxy_pass參數配置帶不帶‘/’


1. proxy_pass 配置的url后面,不加'/',那么重定向后,追加location后的路徑。
比如server_name: 10.9.11.225
location /proxy1/{
proxy_pass http://10.9.11.166:8540/;
}
location  /proxy2/ {
          proxy_pass http://10.9.11.166:8540/haha/;
}
如果訪問 10.9.11.225/proxy1/   會代理到http://10.9.11.166:8540/
如果訪問 10.9.11.225/proxy2/   會代理到http://10.9.11.166:8540/haha/

2. 如果proxy_pass配置的url后面,不加'/',那么重定向后,整個替換location后的路徑。
location /proxy3/{
proxy_pass http://10.9.11.166:8540;
}
location  /proxy4/ {
          proxy_pass http://10.9.11.166:8540/haha;
}
訪問http://10.9.11.225/proxy/就會被反向代理到http://10.9.11.166:8540/proxy/
訪問http://10.9.11.225/proxy4/index.html就會被反向代理到http://10.9.11.166:8540/hahaindex.html

3.rewrite 參數簡介

location /momo/{

  rewrite ^/momo/?(.*) /$1 break;

  proxy_pass http://front;

  ...

}

uri>>>lixiaoxuan.com/momo/test/hello? 重定向到了哪里?
是front/momo/test/hello......嗎?   答案是錯誤的,因為有一個rewrite,這個配置又是干啥的?
基本語法: rewrite regex replacement [flag];
上下文:server, location, if
flag:break,重寫后,不發起新的請求,直接往下走

匹配'/maimai/'重寫后,uri變成了front/test/hello?
再根據front配置重定向到其他

 


免責聲明!

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



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