美文网首页
nginx location / 区别

nginx location / 区别

作者: 木人呆呆 | 来源:发表于2022-02-22 16:54 被阅读0次

测试代码

nginx服务器地址及端口:127.0.0.1:80
后端服务地址及端口:127.0.0.1:8080
测试URL:http://127.0.0.1:80/api/upload

一 . 配置1

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

实际访问 http://127.0.0.1:8080/upload

二 . 配置2

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

实际访问 http://127.0.0.1:8080//upload

三 . 配置3

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

实际访问 http://127.0.0.1:8080/api/upload

四 . 配置四

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

实际访问 http://127.0.0.1:8080/api/upload

五 . 配置5

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

实际访问 http://127.0.0.1:8080/server/upload

六 . 配置6

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

实际访问 http://127.0.0.1:8080/server//upload

七 . 配置7

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

实际访问 http://127.0.0.1:8080/serverupload

八 . 配置8

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目录部分

相关文章

网友评论

      本文标题:nginx location / 区别

      本文链接:https://www.haomeiwen.com/subject/hhbglrtx.html