1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > nginx访问目录是没加/的重定向控制

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

时间:2021-12-10 18:50:46

相关推荐

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

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

指令

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

配置

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

测试

[root@python vhast]# curl :8088/first -IHTTP/1.1 301 Moved PermanentlyServer: nginx/1.15.9Date: Wed, 10 Jul 10:30:04 GMTContent-Type: text/htmlContent-Length: 169Connection: keep-aliveLocation: /first/

修改配置

server {server_name ;server_name_in_redirect off;listen 8088;#absolute_redirect off;root html/;}

测试

[root@python vhast]# curl :8088/first -IHTTP/1.1 301 Moved PermanentlyServer: nginx/1.15.9Date: Wed, 10 Jul 10:31:21 GMTContent-Type: text/htmlContent-Length: 169Location: :8088/first/Connection: keep-alive

测试加主机名

root@python vhast]# curl -H "Host:aaa" localhost:8088/first -IHTTP/1.1 301 Moved PermanentlyServer: nginx/1.15.9Date: Wed, 10 Jul 10:34:36 GMTContent-Type: text/htmlContent-Length: 169Location: http://aaa:8088/first/Connection: keep-alive

修改配置

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

测试

[root@python vhast]# curl -H "Host:aaa" localhost:8088/first -IHTTP/1.1 301 Moved PermanentlyServer: nginx/1.15.9Date: Wed, 10 Jul 10:36:46 GMTContent-Type: text/htmlContent-Length: 169Location: :8088/first/Connection: keep-alive

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。