Nginx
一、是否加斜杠的区别
1、不加斜杠(保持你原来写的)nginx复制
location ^~ /customer/ {
proxy_pass http://localhost:3000;
}效果:域名:端口/customer/foo/bar → 域名:端口/customer/foo/bar 把 /customer/ 原封不动带过去。
2、加斜杠(你刚问的)nginx复制
location ^~ /customer/ {
proxy_pass http://localhost:3000;
}效果:域名:端口/customer/foo/bar → 域名:端口/foo/bar 把 /customer/ 这一段吃掉,后端 3000 端口收到的路径就不再带 /customer 所以
- 如果后端服务本身就挂在 /customer 下,用 写法 1(不加 /)。
- 如果后端服务跑在根路径 /,而你又不想改代码,用 写法 2(加 /)。
