nginx 访问url时如何自动添加加斜杠

运行环境

nginx:1.15.1
windows: 2003/2008/7

需求描述

使用 nginx 配置tomcat集群后,访问web时,无法正常打开页面,需要在test后面添加斜杠/,才能正常访问:
http://127.0.0.1/test 无法访问
http://127.0.0.1/test/ 访问正常

nginx 配置方式如下:

配置服务器集群组
upstream backend{
# server 1
server 127.0.0.1:8080 weight=1 max_fails=3 fail_timeout=30s;
# server 2
server 127.0.0.1:8180 weight=1 max_fails=3 fail_timeout=30s;
}
server {
# 其他配置项
# 映射服务器集群
location /test/{
proxy_pass http://backend;
}
}

解决办法

修订server配置,将 /test 替换为 /test/,问题解决。

server {
# 其他配置项
# 映射服务器集群
location /test/{
proxy_pass http://backend;
}
}

猜你喜欢

转载自blog.csdn.net/huryer/article/details/81091964