THS-Location斜杠区别详解

1 、location和proxy_pass都带/,则真实地址不带location匹配目录

location /api/ {

proxy_pass http://127.0.0.1:8080/;

}

访问地址:www.test.com/api/upload-->http://127.0.0.1:8080/upload

2 、location不带/,proxy_pass带/,则真实地址会带/

location /api {

proxy_pass http://127.0.0.1:8080/;

}

访问地址:www.test.com/api/upload-->http://127.0.0.1:8080//upload

3 、location带/,proxy_pass不带/,则真实地址会带location匹配目录/api/

location /api/ {

proxy_pass http://127.0.0.1:8080;

}

访问地址:www.test.com/api/upload-->http://127.0.0.1:8080/api/upload

4 、location和proxy_pass都不带/,则真实地址会带location匹配目录/api/

location /api {

proxy_pass http://127.0.0.1:8080;

}

访问地址:www.test.com/api/upload-->http://127.0.0.1:8080/api/upload

5 、同1,但proxy_pass带地址

location /api/ {

proxy_pass http://127.0.0.1:8080/server/;

}

访问地址:www.test.com/api/upload-->http://127.0.0.1:8080/server/upload

6 、同2,但proxy_pass带地址,则真实地址会多个/

location /api {

proxy_pass http://127.0.0.1:8080/server/;

}

访问地址:www.test.com/api/upload-->http://127.0.0.1:8080/server//upload

7 、同3,但 proxy_pass带地址,则真实地址会直接连起来

location /api/ {

proxy_pass http://127.0.0.1:8080/server;

}

访问地址:www.test.com/api/upload-->http://127.0.0.1:8080/serverupload

8 、同4,但proxy_pass带地址,则真实地址匹配地址会替换location匹配目录

location /api {

proxy_pass http://127.0.0.1:8080/server;

}

访问地址:www.test.com/api/upload-->http://127.0.0.1:8080/server/upload

总结:

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

2、proxy_pass代理地址端口后无任何,转发后地址:代理地址+访问URL目录部分。

3、有时更改location和proxy_pass后浏览器查看不生效,有可能是启用缓存的原因,此时需要禁用缓存:add_header Cache-Control no-cache;

相关推荐
ljh5746491195 小时前
linux awk 命令
linux·运维·chrome
我是谁??5 小时前
Rocky9+ Docker + 容器内Linux桌面环境 + Web远程
运维·docker·容器
阿虎儿5 小时前
Ubuntu 如何开启 Root 用户 SSH 登录
运维
the sun345 小时前
Linux驱动开发:环境准备与报错处理
linux·运维·服务器
彭泽布衣5 小时前
Linux如何指定源端口打流
linux·运维·网络
Ciel_75215 小时前
OpenClaw 深度进阶:记忆系统、多智能体架构与自动化调度全解析
运维·自动化
晨晖26 小时前
Linux命令3
linux·运维·服务器
素雨迁喜6 小时前
Linux平台下git工具的使用
linux·运维·git
bing_feilong7 小时前
Ubuntu Tips
linux·运维
SeanDe7 小时前
【Linux `top` 命令详解(结合截图逐行拆解)】
linux·运维·服务器