测试需求,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得第一个域名,自己配置上端口
重启生效。
Syntax: | server_name_in_redirect |
---|---|
Default: |
server_name_in_redirect off; |
Context: |
http , server , location
|
Enables or disables the use of the primary server name, specified by the server_name directive, in absolute redirects issued by nginx. When the use of the primary server name is disabled, the name from the “Host” request header field is used. If this field is not present, the IP address of the server is used.
Syntax: | port_in_redirect |
---|---|
Default: |
port_in_redirect on; |
Context: |
http , server , location
|
Enables or disables specifying the port in absolute redirects issued by nginx.
The use of the primary server name in redirects is controlled by the server_name_in_redirect directive.