nginx location / 區別


nginx服務器地址及端口:127.0.0.1:80
后端服務地址及端口:127.0.0.1:8080
測試URL:http://127.0.0.1:80/api/upload

nginx配置:

location /api/ {
    proxy_pass http://127.0.0.1:8080/;
}

實際訪問:http://127.0.0.1:8080/upload

nginx配置:

location /api {
    proxy_pass http://127.0.0.1:8080/;
}

實際訪問:http://127.0.0.1:8080//upload

nginx配置:

location /api/ {
    proxy_pass http://127.0.0.1:8080;
}

實際訪問:http://127.0.0.1:8080/api/upload

nginx配置:

location /api {
    proxy_pass http://127.0.0.1:8080;
}

實際訪問:http://127.0.0.1:8080/api/upload

nginx配置:

location /api/ {
    proxy_pass http://127.0.0.1:8080/server/;
}

實際訪問:http://127.0.0.1:8080/server/upload

nginx配置:

location /api {
    proxy_pass http://127.0.0.1:8080/server/;
}

實際訪問:http://127.0.0.1:8080/server//upload

nginx配置:

location /api/ {
    proxy_pass http://127.0.0.1:8080/server;
}

實際訪問:http://127.0.0.1:8080/serverupload

nginx配置:

location /api {
    proxy_pass http://127.0.0.1:8080/server;
}

實際訪問:http://127.0.0.1:8080/server/upload

總結
1.proxy_pass代理地址端口后有目錄(包括 / ),轉發后地址:代理地址+訪問URL目錄部分去除location匹配目錄
2.proxy_pass代理地址端口后無任何,轉發后地址:代理地址+訪問URL目錄部分


免責聲明!

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



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