NGINX配置之二: nginx location proxy_pass 后面的url 加與不加/的區別.


這里我們分4種情況討論

這里我們請求的網站為:192.168.1.123:80/static/a.html

整個配置文件是

server{
port  80,
server name  192.168.1.123

location /static{
proxy_pass  192.168.2.321:81
}

location /static{
proxy_pass  192.168.2.321:81/
}

location /static/{
proxy_pass  192.168.2.321:81
}

location /static/{
proxy_pass  192.168.2.321:81/
}

 

我們分開來講:

第一種:

location后沒有/      轉發網站沒有/
#192.168.1.123->server name
# :80 ---------> port
#/statc ------->location
#/a.html ------>proxy_pass 

location /static{
proxy_pass  192.168.2.321:81
}
最后網址經過nginx轉向到的網址是 192.168.2.321:81/static/a.html

第二種:

location后沒有/      轉發網站有/
#192.168.1.123---->server name
# :80 ------------> port
#/statc ---------->location
#/a.html --------->proxy_pass 

location /static{
proxy_pass  192.168.2.321:81/
}
最后網址經過nginx轉向到的網址是 192.168.2.321:81/a.html

第三種:
location后有/      轉發網站沒有/
#192.168.1.123-->server name
# :80 ------------> port
#/statc/ ---------->location
#a.html --------->proxy_pass 

location /static/{
proxy_pass  192.168.2.321:81
}
最后網址經過nginx轉向到的網址是 192.168.2.321:81/static/a.html
第四種:
location后有/ 轉發網站有/
#192.168.1.123-->server name
# :80 ------------> port
#/statc/ ---------->location(path1)
#a.html --------->proxy_pass (path2)

location /static/{
proxy_pass  192.168.2.321:81/
}
最后網址經過nginx轉向到的網址是 192.168.2.321:81/a.html

總結:
從這四種我們可以的看出,當nginx里面匹配時可以把端口后的參數分為path1+path2(其中我在上方標注的location屬於path1,
proxy_pass屬於path2)
proxy_pass  
里面是ip:port+/時nginx最后匹配的網址是 proxy_pass的內容加上path2
里面是
ip:port時nginx最后匹配的網址是 proxy_pass的內容加上path1+path2
 
        

 


免責聲明!

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



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