Nginx斜杠艺术
0
以前没有用过Nginx的路径配置,这才发现原来配置斜杠和不配置斜杠区别这么大:
# Nginx:localhost:80
# Tomcat:localhost:8080
# 访问:http://localhost:80/acgist/api/abc
location /acgist/ {
proxy_pass http://localhost:8080/;
}
# 实际Tomcat地址:http://localhost:8080/api/abc
location /acgist {
proxy_pass http://localhost:8080/;
}
# 实际Tomcat地址:http://localhost:8080//api/abc
location /acgist/ {
proxy_pass http://localhost:8080;
}
# 实际Tomcat地址:http://localhost:8080/acgist/api/abc
location /acgist {
proxy_pass http://localhost:8080;
}
# 实际Tomcat地址:http://localhost:8080/acgist/api/abc
location /acgist/ {
proxy_pass http://localhost:8080/server/;
}
# 实际Tomcat地址:http://localhost:8080/server/api/abc
location /acgist {
proxy_pass http://localhost:8080/server/;
}
# 实际Tomcat地址:http://localhost:8080/server//api/abc
location /acgist/ {
proxy_pass http://localhost:8080/server;
}
# 实际Tomcat地址:http://localhost:8080/serverapi/abc
location /acgist {
proxy_pass http://localhost:8080/server;
}
# 实际Tomcat地址:http://localhost:8080/server/api/abc
最主要的区别就是代理最后是否有斜杠,斜杠会替换匹配路径信息。
root
和alias
就不描述了。
proxy_pass
后面的斜杠会去掉location
路径匹配前缀。