nginx访问目录是没加/的重定向控制

static 模块提供了root与alias功能;发现目标是目录时;但URI末尾未加/时;会返回301重定向;重定向后会加/

指令

 

Syntax: server_name_in_redirect on | off;# 控制返回那个域名
Default: server_name_in_redirect off; 
Context: http, server, location
Syntax: port_in_redirect on | off;  #控制返回的端口
Default: port_in_redirect on; 
Context: http, server, location
Syntax: absolute_redirect on | off;  #返回重定向时时否添域名,默认是会添域名
Default: absolute_redirect on; 
Context: http, server, location

  

配置

[root@python vhast]# cat dir.conf 
server {
	server_name www.dir.com fwe.dir.com;  #第一个为主域名;第二个为辅助域名
	server_name_in_redirect off;
	listen 8088;
	absolute_redirect off;
	root html/;
}

  测试

[root@python vhast]# curl www.dir.com:8088/first -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.15.9
Date: Wed, 10 Jul 2019 10:30:04 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: /first/

  修改配置

server {
	server_name www.dir.com fwe.dir.com;
	server_name_in_redirect off;
	listen 8088;
	#absolute_redirect off;
	root html/;
}

  测试

[root@python vhast]# curl www.dir.com:8088/first -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.15.9
Date: Wed, 10 Jul 2019 10:31:21 GMT
Content-Type: text/html
Content-Length: 169
Location: http://www.dir.com:8088/first/
Connection: keep-alive

  测试加主机名

root@python vhast]# curl -H "Host:aaa" localhost:8088/first -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.15.9
Date: Wed, 10 Jul 2019 10:34:36 GMT
Content-Type: text/html
Content-Length: 169
Location: http://aaa:8088/first/
Connection: keep-alive

  修改配置

[root@python vhast]# cat dir.conf 
server {
	server_name www.dir.com fwe.dir.com;
	server_name_in_redirect on;  #表示修改为主域名在返回的URI里
	listen 8088;
	#absolute_redirect off;
	root html/;
}

  测试

[root@python vhast]# curl -H "Host:aaa" localhost:8088/first -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.15.9
Date: Wed, 10 Jul 2019 10:36:46 GMT
Content-Type: text/html
Content-Length: 169
Location: http://www.dir.com:8088/first/
Connection: keep-alive

  

转载于:https://www.cnblogs.com/rdchenxi/p/11171349.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值