Nginx CONTENT阶段 static模块
L63-65



alias指令
syntax: alias path;# 静态文件路径 alias不会将请求路径后的路径添加到 path中
context : location;
root指令
syntax : root path; #静态文件路径 root会将请求路径后添加的 path中
context : http,server,location,if in location
location /root {
root html;
}
location /alias{
alias html;
}
location ~/root/(\w+\.txt){
root html/first/$;
}
location ~/alias/(\w+\.txt){
alias html/first/$;
}
访问 http://xxxx/root 返回404 通过error日志 可以看到 会在html后加上root目录
访问 http://xxxx/alias 返回nginx主页面 返回正确
访问 http://xxxx/root/1.txt 返回404
访问 http://xxxx/alias/1.txt 则返回1.txt内容

static模块三个变量
request_filename : 访问文件的完整路径包括扩展名
document_root : 由URI和root/alias规则生成的文件夹路径
realpath_root : 将document_root软连接替换成真实路径
location /realpath{
alias html/realpath;
return '$request_filename:$document_root:$realpath_root\n';
}
访问 http://xxxx/realpath/1.txt 则返回 /usr/local/nginx/html/realpath/1.txt:/usr/local/nginx/html/realpath:/usr/local/nginx/html/realpath 输出的路径
当用户访问资源时没有在末尾加反斜杠的时候 NGINX会返回一个301的重定向
指令 absolute_redirect
syntax: on | off;
default : on;
context : http,server,location
server {
listen ;
server_name localhost;
absolute_redirect off; #关闭的时候
port_in_redirect on;
}
演示:当关闭absolute_redirect的时候 curl http://116.196.123.9/alias -i
当访问后 看到头部是不带域名的
Server: nginx/1.14.2
Date: Fri, 15 Feb 2019 08:26:21 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: /alias/ #我们看到没有完整域名
当打开的时候 就有 Location: http://192.xxx.xxx.1/alias/
指令 port_in_redirect
syntax : on | off;
defaut : on;
context : http,server,location;
指令 server_name_in_redirect 主要控制 是否返回的 host域名 还是server_name主域名
syntax : on | off;
default : off;
context : http,server,location;
Nginx CONTENT阶段 static模块的更多相关文章
- Nginx CONTENT阶段 concat模块
L67 concat_delimiter : 根据js 指定 分隔符 比如 “|” 那么每个文件分隔符为 “|” concat_types : 指定要合并文件的类型 concat_unique : s ...
- Nginx CONTENT阶段 autoindex、index模块
L 66 autoindex 指令 syntax : on | off; default : off; context : http,server,location; autoindex_exact_ ...
- Nginx执行阶段
Nginx 介绍 Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器. Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮 ...
- openresty开发系列35--openresty执行流程之5内容content阶段
openresty开发系列35--openresty执行流程之5内容content阶段 content 阶段 ---init阶段---重写赋值---重写rewrite---access content ...
- Nginx的第一个模块-HelloWorld
麻雀虽小,五脏俱全,小小的Hello World盛行于程序世界,就在于其代码虽短,但要真正运行起来,需要我们略通基本语法,稍懂编译运行环境,知晓操作过程,最后,还有一颗持之以恒,不怕折腾的心.前一阵子 ...
- Nginx 高级配置-第三方模块编译
Nginx 高级配置-第三方模块编译 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 第三模块是对nginx 的功能扩展,第三方模块需要在编译安装Nginx 的时候使用参数--add ...
- Nginx一致性哈希模块的Lua实现
Nginx一致性哈希模块的Lua重新实现 技术背景: 最近在工作中使用了nginx+redis 的架构,redis在后台做分布式存储,每个redis都存放不同的数据,这些数据都是某门户网站通过Hado ...
- nginx图片过滤处理模块http_image_filter_module安装配置笔记
http_image_filter_module是nginx提供的集成图片处理模块,支持nginx-0.7.54以后的版本,在网站访问量不是很高磁盘有限不想生成多余的图片文件的前提下可,就可以用它实时 ...
- yum安装下的nginx,如何添加模块,和添加第三方模块
需求:生产有个接口是通过socket通信.nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信. 实现方法:Centos7.2下yum直接安装的nginx, ...
随机推荐
- flask 路由和视图
路由设置的俩种方式 @app.route('/xxx') def index(): return 'index' ------------------------------------------ ...
- 【Codeforces Round 1114】Codeforces #538 (Div. 2)
Codeforces Round 1114 这场比赛做了\(A\).\(C\).\(D\).\(E\),排名\(134\). \(B\)题做了很长时间,好不容易最后一分钟\(Pretest\ Pass ...
- synchronized和Lock的异同
JAVA语言使用两种机制来实现堆某种共享资源的同步,synchronized和Lock.其中,synchronized使用Object对象本身的notify.wait.notifyAll调度机制,而l ...
- Codeforces 999D Equalize the Remainders (set使用)
题目连接:Equalize the Remainders 题意:n个数字,对m取余有m种情况,使得每种情况的个数都为n/m个(保证n%m=0),最少需要操作多少次? 每次操作可以把某个数字+1.输出最 ...
- Linux常用命令行
实时查看日志runtime.log最后100行 tail -f -n 100 runtime.log
- Flutter - BottomNavigationBar底部导航栏切换后,状态丢失
如果你用过BottomNavigationBar.TabBar.还有Drawer,你就会发现,在切换页面之后,原来的页面状态就会丢失. 要是上一页有一个数据列表,很多数据,你滚动到了下头,切换页面后, ...
- 手机APP自动化之uiautomator2 +python3 UI自动化
题记: 之前一直用APPium直到用安卓9.0 发现uiautomatorviewer不支持安卓 9.0,点击截屏按钮 一直报错,百度很久解决方法都不可以,偶然间看见有人推荐:uiautomator ...
- [朴孝敏][Ooh La La]
歌词来源:http://music.163.com/#/song?id=484058960 作曲 : Damon Sharpe/Jimmy Burney/Adam Kapit [作曲 : Damon ...
- PHP从入门到精通(二)
PHP从入门到精通 之PHP中的函数 各位开发者朋友大家好,自上次更新PHP的相关知识,得到了大家的广泛支持.PHP的火爆程度不言而喻,函数作为PHP中极为重要的部分,应诸位的支持,博主继续跟进更新 ...
- 百度之星-day2-1004-二分答案
由于序列有序,求其中一个最优解,二分答案即可,注意二分时上边界满足才保存 #include<iostream> #include<stdio.h> #include<st ...