nginx的proxy_pass路徑轉發規則淺析(末尾/問題)

源地址 :html

https://www.zifangsky.cn/917.htmlnginx

 

 

一 location匹配路徑末尾沒有 /

 

此時proxy_pass後面的路徑必須拼接location的路徑:服務器

 

  • 外面訪問:http://192.168.1.30/sta/sta1.html
  • 至關於訪問:http://192.168.1.31/sta/sta1.html

注:這裏也能夠寫成:「proxy_pass http://192.168.1.31/sta/;」。固然,不推薦使用上面這種寫法cookie

二 location匹配路徑末尾有 /

此時proxy_pass後面的路徑須要分爲如下四種狀況討論:app

(1)proxy_pass後面的路徑只有域名且最後沒有 /:

 

 

  • 外面訪問:http://192.168.1.30/sta/sta1.html
  • 至關於訪問:http://192.168.1.31/sta/sta1.html

(2)proxy_pass後面的路徑只有域名同時最後有 /:

 

 

  • 外面訪問:http://192.168.1.30/sta/sta1.html
  • 至關於訪問:http://192.168.1.31/sta1.html

(3)proxy_pass後面的路徑還有其餘路徑可是最後沒有 /:

 

  • 外面訪問:http://192.168.1.30/sta/sta1.html
  • 至關於訪問:http://192.168.1.31/abcsta1.html

(4)proxy_pass後面的路徑還有其餘路徑同時最後有 /:

 

 

  • 外面訪問:http://192.168.1.30/sta/sta1.html
  • 至關於訪問:http://192.168.1.31/abc/sta1.html

附:在nginx上面配置APK文件下載路徑:spa

 

  • 外面訪問:http://test.com/h5/appdownload/Demo_1.0.0.apk
  • 至關於訪問:http://192.168.1.31/Demo_1.0.0.apk

每次更新apk文件,只須要上傳新的apk文件到192.168.1.31服務器,而後再更新對外的下載地址爲http://test.com/h5/appdownload/newName.apk便可,並不須要更改nginx的任何配置code

相關文章
相關標籤/搜索