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得第一個域名,自己配置上端口

重啟生效。

 

Syntax: server_name_in_redirect on | off;
Default:
server_name_in_redirect off;
Context: httpserverlocation

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 on | off;
Default:
port_in_redirect on;
Context: httpserverlocation

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.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM