Nginx代理中使用斜杠的區(qū)別小結(jié)
代理地址是:http://127.0.0.1:8000
總結(jié):代理地址加斜杠替換,代理地址不加斜杠拼接
1、代理地址不加斜杠
# 請求路徑為:http://127.0.0.1:8080/api/getInfo # 實(shí)際代理為:http://127.0.0.1:8000/api/getInfo location ^~/api/ { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; }
# 請求路徑為:http://127.0.0.1:8080/api/getInfo # 實(shí)際指向?yàn)椋篽ttp://127.0.0.1:8000/api/getInfo location ^~/api { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; }
location定位的路徑設(shè)置,是否帶斜杠,沒有關(guān)系。
2、代理地址 + 斜杠
# 請求路徑為:http://127.0.0.1:8080/api/getInfo # 實(shí)際代理為:http://127.0.0.1:8000/getInfo location ^~/api/ { proxy_pass http://127.0.0.1:8000/; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; }
# 請求路徑為:http://127.0.0.1:8080/api/getInfo # 實(shí)際代理為:http://127.0.0.1:8000//getInfo location ^~/api { proxy_pass http://127.0.0.1:8000/; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; }
如果代理地址加了斜杠,不管location是否加斜杠,api路徑都省略了。
3、代理地址 + 后綴
# 請求路徑為:http://127.0.0.1:8080/api/getInfo # 實(shí)際代理為:http://127.0.0.1:8000/wxgetInfo location ^~/api/ { proxy_pass http://127.0.0.1:8000/wx; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; }
# 請求路徑為:http://127.0.0.1:8080/api/getInfo # 實(shí)際代理為:http://127.0.0.1:8000/wx/getInfo location ^~/api { proxy_pass http://127.0.0.1:8000/wx; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; }
如果location帶斜杠,會省略url中的斜杠。
4、代理地址 + 后綴 + 斜杠
# 請求路徑為:http://127.0.0.1:8080/api/getInfo # 實(shí)際代理為:http://127.0.0.1:8000/wx/getInfo location ^~/api/ { proxy_pass http://127.0.0.1:8000/wx/; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; }
# 請求路徑為:http://127.0.0.1:8080/api/getInfo # 實(shí)際代理為:http://127.0.0.1:8000/wx//getInfo location ^~/api { proxy_pass http://127.0.0.1:8000/wx/; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; }
其他
精確匹配:server_name www.test.com ;
左側(cè)通配:server_name *.test.com ;
右側(cè)統(tǒng)配:server_name www.test.* ;
正則匹配:server_name ~^www\.test\.*$ ;
匹配優(yōu)先級:精確匹配 > 左側(cè)通配符匹配 > 右側(cè)通配符匹配 > 正則表達(dá)式匹配
#直接返回狀態(tài)碼 location / { return 404; } #返回狀態(tài)碼 + 一段文本 location / { return 404 "pages not found"; } #返回狀態(tài)碼 + 重定向地址 location / { return 302 /blog ; } #返回重定向地址 location / { return https://www.test.com ; }
# http強(qiáng)制跳轉(zhuǎn)到https server { listen 80; server_name test.com; rewrite ^(.*)$ https://$server_name$1 permanent; }
到此這篇關(guān)于Nginx代理中使用斜杠的區(qū)別小結(jié)的文章就介紹到這了,更多相關(guān)Nginx代理斜杠內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx同一個域名配置多個項(xiàng)目的實(shí)現(xiàn)方法
這篇文章主要介紹了Nginx同一個域名配置多個項(xiàng)目的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03Nginx配置編寫時(shí)支持邏輯運(yùn)算與大小寫字母轉(zhuǎn)換的方法
這篇文章主要介紹了Nginx配置編寫時(shí)支持邏輯運(yùn)算與大小寫字母轉(zhuǎn)換的方法,其中大小寫字母轉(zhuǎn)換是以lower upper case模塊來實(shí)現(xiàn),需要的朋友可以參考下2016-01-01nginx rewrite 偽靜態(tài)配置參數(shù)和使用例子
nginx下偽靜態(tài)配置參數(shù)詳細(xì)說明,使用nginx的朋友,nginx rewrite 偽靜態(tài)配置參數(shù)和使用例子 附正則使用說明2010-07-07Nginx在Windows下的安裝及環(huán)境配置(將nginx作為服務(wù)運(yùn)行)
這篇文章主要介紹了Nginx在Windows下的安裝及環(huán)境配置,主要是將nginx作為服務(wù)運(yùn)行,需要的朋友可以參考下2018-11-11Linux Nginx下SSL證書安裝方法及WordPress CDN配置
這篇文章主要介紹了Linux Nginx下SSL證書安裝方法及WordPress CDN配置,需要的朋友可以參考下2017-08-08