nginx location “/” 的几种情况总结


转至:https://www.cnblogs.com/she11s/p/14456301.html

先上总结:

1.proxy_pass代理地址端口后有目录(包括 / ),转发后地址:代理地址+访问URL目录部分去除location匹配目录
2.proxy_pass代理地址端口后无任何,转发后地址:代理地址+访问URL目录部分

测试环境:

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:80/api/upload
实际访问:http://127.0.0.1:8080/upload

nginx配置:

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

访问地址:http://127.0.0.1:80/api/upload
实际访问:http://127.0.0.1:8080//upload

nginx配置:

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

访问地址:http://127.0.0.1:80/api/upload
实际访问:http://127.0.0.1:8080/api/upload

nginx配置:

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

访问地址:http://127.0.0.1:80/api/upload
实际访问: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:80/api/upload
实际访问: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:80/api/upload
实际访问: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:80/api/upload
实际访问:http://127.0.0.1:8080/serverupload

nginx配置:

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

访问地址:http://127.0.0.1:80/api/upload
实际访问:http://127.0.0.1:8080/server/upload

声明:鹅石壳儿|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - nginx location “/” 的几种情况总结


Carpe Diem and Do what I like