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
nginx访问目录是没加/的重定向控制的更多相关文章
- SELinux 对nginx访问目录的影响
centos新装的系统,用yum 安装的nginx . 因用yum 安装的nginx 默认目录在/usr下面. 当SELinux开启时,将会禁止访问设置在其他路径下的地址.比如我设置server 中 ...
- nginx 访问目录403
centos7.2默认安装好nginx后,会在/usr/share/nginx/html下作为主目录 但是如果想访问下面的目录会发现没有权限,返回403错误 这时候要注意在/etc/nginx/ngi ...
- centos7 nginx访问目录403解决
查看 /usr/sbin/sestatusSELinux status是不是enabled 然后 vi /etc/selinux/config修改:SELINUX=disabledreboot
- 修改nginx的访问目录以及遇到的403错误修改总结
对于这个问题困扰了我好几天,前篇文章介绍了图片服务器的使用,但是两个服务器如何进行通话访问呢,即如何通过nginx来访问ftp服务器上的资源文件呢,这里面需要修改nginx的配置文件(vi /usr/ ...
- nginx配置目录列表访问权限
我们知道apache httpd默认情况下会显示访问目录的文件列表,但是nginx访问时如果目录下面没有默认首页,那么会返回403 Forbidden的错误,表示没有权限访问,比如根目录就是nginx ...
- nginx配置目录访问&用户名密码控制
背景 项目上需要一些共享目录让外地同事可以网页访问对应的文件,且受权限控制: 现有环境: centos nginx 你可以了解到以下内容: 配置nginx开启目录访问 并配置nginx用户名和密码进行 ...
- nginx默认访问目录时显示403错误
author :headsen chen date: 2018-04-25 17:17:25 nginx安装完成后默认的http页面里访问目录的话会报403的错误: 和Apache进行比较,Apac ...
- Nginx访问VM虚拟机CentOS 7系统与本地Windows系统共享目录403
用VMware安装了CentOS7系统,并搭建了Nginx,MySQL,PHP的web项目运行环境,为了方便Windows本地主机进行程序调试把Windows本地项目目录共享到了虚拟机CentOS中的 ...
- 决解nginx代理的django项目的admin站点无法访问,和没样式的问题。
首先我们先解决无法访问admin站点的问题 首先我们先修改一下nginx的配置,添加红色框框的部分. 然后重新启动一下nginx 访问一下admin站点 发现没有样式了. 我们先修改/fast_foo ...
随机推荐
- ES6 Set和Map的那点事
Set 1.Set特点 类数组 新增数据结构 是构造函数 成员值唯一 注重独一无二的特征 2.Set实例的常用方法 console.log('------------Set操作方法-------- ...
- Spring Cloud netflix feign【服务间通信】
一.简介 1,进程间通讯的本质是交换消息 2,服务间通信的两种方式 (1)RESTFul风格 (2)RPC风格 (3)两种风格的比较 3.基于RESTFul风格服务调用模型 4.基于Spring Cl ...
- django-cors-headers
django-cors-headers介绍 一个Django应用程序,向响应头中添加跨域资源共享(CORS)头.这允许从其他来源向Django应用程序发出浏览器内请求,当然也可以自定义中间件然后添加响 ...
- Jmeter 测试结果分析之聚合报告简介
聚合报告(aggregate report) 对于每个请求,它统计响应信息并提供请求数,平均值,最大,最小值,错误率,大约吞吐量(以请求数/秒为单位)和以kb/秒为单位的吞吐量. 吞吐量是以取样目标点 ...
- 压缩/批量压缩/合并js文件
写在前面 如果文件少的话,直接去网站转化一下就行. http://tool.oschina.net/jscompress?type=3 1.压缩单个js文件 cnpm install uglify-j ...
- 搭建分布式hadoop环境的前期准备---需要检查的几个点
前期准备: jdkhostnamehostsdate安全机制firewallwindows 域名映射 具体的操作见下面 1.看看自己是否已经配置了别名了(linux别名的配置可以参考博文:自己cent ...
- python学习之matplotlib绘制动图(FuncAnimation()参数)
1.函数FuncAnimation(fig,func,frames,init_func,interval,blit)是绘制动图的主要函数,其参数如下: a.fig 绘制动图的画布名称 b.func自定 ...
- Ubuntu18.04配置中文输入法(系统自带的)
Ubuntu18.04配置中文输入法 之前安装Ubuntu18.04的时候选择了english,现在要配置中文的输入法 打开系统设置 点击其中的工具按钮左边第一个 点击管理语言 ==如果系统刚安装可能 ...
- Bug搬运工-CSCvi02106 :Cisco 2800, 3800, 1560 APs: when connected to a Cisco Switch CDP-4-DUPLEX_MISMATCH log is seen
Cisco 2800, 3800, 1560 APs: when connected to a Cisco Switch CDP-4-DUPLEX_MISMATCH log is seen CSCvi ...
- Android学习01
一.线性布局(Linerlayout)和相对布局(Relativelayout) 线性布局可以分为水平线性布局(vertical)和垂直线性布局(horizontal)这两种布局方式weight权重按 ...