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.

 

转载于:https://www.cnblogs.com/zhengchunyuan/p/10032319.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值