nginx url问题

测试需求,url自动加/后,发现重定向不带端口,即为 test.a.com:3443/abc  nginx自动重定向301到 test.a.com/abc,端口消失。

分析可能和nginx默认配置server_name_in_redirect 与 port_in_redirect 有关

1、server_name_in_redirect on(默认),URL 重定向为: server_name 中的第一个域名 + 目录名 + /;
2、server_name_in_redirect off,URL 重定向为: 原 URL 中的域名 + 目录名 + /。
If server_name_in_redirect is on, then Nginx will use the first value of the server_name directive for redirects. If server_name_in_redirect is off, then nginx will use the requested Host header.

更改nginx配置

server_name test.a.com:3443;
server_name_in_redirect on

即强制使用server_name得第一个域名,自己配置上端口

重启生效。

猜你喜欢

转载自www.cnblogs.com/zhengchunyuan/p/10032319.html