nginx 的 content阶段的root指令与alias指令
root 与alias指令
Syntax: alias path;
Default: —
Context: location Syntax: root path;
Default: root html;
Context: http, server, location, if in location
功能:将URI映射为文件路径,以静态文件返回
差别:root 会将完整的URI映射进文件路径中;alias只会将location后面的文件映射进location中
示例
server {
server_name root.com;
error_log logs/root_error.log info;
access_log logs/root.log main;
location /root {
root html; #表示映射本地html/root
}
location /alias {
alias html; #访问root.com/alias 命中本地/data/web/html
}
location ~ /root/(\w+\.txt) {
root html/first/$1;#访问这个root.com/root/1.txt,命中本地的/data/web/html/first/1.txt/root/1.txt
}
location ~ /alias/(\w+\.txt) {
alias html/first/$1; # 访问这个curl root.com/alias/1.txt,命中本地的/data/web/html/first/1.txt
}
}
日志
[root@python vhast]# curl root.com/root
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.15.9</center>
</body>
</html>
[root@python vhast]# curl root.com/root/1.txt
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.15.9</center>
</body>
</html>
[root@python vhast]# curl root.com/alias
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.15.9</center>
</body>
</html>
[root@python vhast]# curl root.com/alias/1.txt
first 日志
192.168.183.4 - - [10/Jul/2019:16:25:01 +0800] "GET /root HTTP/1.1" 404 153 "-" "curl/7.29.0" "-" "/root" "-" "/data/web/html" "/data/web/html/root"
192.168.183.4 - - [10/Jul/2019:16:30:16 +0800] "GET /root/1.txt HTTP/1.1" 404 153 "-" "curl/7.29.0" "-" "/root/1.txt" "-" "/data/web/html/first/1.txt" "/data/web/html/first/1.txt/root/1.txt"
192.168.183.4 - - [10/Jul/2019:16:31:51 +0800] "GET /alias HTTP/1.1" 301 169 "-" "curl/7.29.0" "-" "/alias" "-" "/data/web/html" "/data/web/html"
192.168.183.4 - - [10/Jul/2019:16:32:09 +0800] "GET /alias/1.txt HTTP/1.1" 200 6 "-" "curl/7.29.0" "-" "/alias/1.txt" "-" "/data/web/html/first/1.txt" "/data/web/html/first/1.txt
三个变量
[root@python vhast]# cat root.conf
server {
server_name root.com;
error_log logs/root_error.log info;
access_log logs/root.log main;
location /root {
root html; #表示映射本地html/root
}
location /alias {
alias html; #访问root.com/alias 命中本地/data/web/html
}
location ~ /root/(\w+\.txt) {
root html/first/$1;#访问这个root.com/root/1.txt,命中本地的/data/web/html/first/1.txt/root/1.txt
}
location ~ /alias/(\w+\.txt) {
alias html/first/$1; # 访问这个curl root.com/alias/1.txt,命中本地的/data/web/html/first/1.txt
}
location /RealPath/ {
alias html/realpath/;
return 200 "$request_filename:$document_root:$realpath_root!\n";
}
}
root@python vhast]# curl root.com/RealPath/
/data/web/html/realpath/:/data/web/html/realpath/:!
nginx 的 content阶段的root指令与alias指令的更多相关文章
- nginx location中root指令和alias指令的区别
nginx location中root指令和alias指令 功能:将url映射为文件路径,以返回静态文件内容 差别:root会将完整的url映射进文件路径中 alias只会将location后的url ...
- Nginx CONTENT阶段 static模块
L63-65 alias指令 syntax: alias path;# 静态文件路径 alias不会将请求路径后的路径添加到 path中 context : location; root指令 sy ...
- (转)Nginx静态服务配置---详解root和alias指令
Nginx静态服务配置---详解root和alias指令 原文:https://www.jianshu.com/p/4be0d5882ec5 静态文件 Nginx以其高性能著称,常用与做前端反向代理服 ...
- Nginx 核心配置-根目录root指令与别名alias指令实战案例
Nginx 核心配置-根目录root指令与别名alias指令实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.试验环境说明 1>.虚拟机环境说明 [root@nod ...
- Nginx静态服务配置---详解root和alias指令
Nginx静态服务配置---详解root和alias指令 静态文件 Nginx以其高性能著称,常用与做前端反向代理服务器.同时nginx也是一个高性能的静态文件服务器.通常都会把应用的静态文件使用ng ...
- 【精选】Nginx模块Lua-Nginx-Module学习笔记(二)Lua指令详解(Directives)
源码地址:https://github.com/Tinywan/Lua-Nginx-Redis Nginx与Lua编写脚本的基本构建块是指令. 指令用于指定何时运行用户Lua代码以及如何使用结果. 下 ...
- Nginx模块Lua-Nginx-Module学习笔记(二)Lua指令详解(Directives)
源码地址:https://github.com/Tinywan/Lua-Nginx-Redis Nginx与Lua编写脚本的基本构建块是指令. 指令用于指定何时运行用户Lua代码以及如何使用结果. 下 ...
- openresty开发系列35--openresty执行流程之5内容content阶段
openresty开发系列35--openresty执行流程之5内容content阶段 content 阶段 ---init阶段---重写赋值---重写rewrite---access content ...
- 你真的了解nginx重定向URI?-rewrite和alias指令
未经允许不得转载!最近发现有博主转载我的文章,并没有跟我打招呼,也没有注明出处!!!! 熟悉Nginx的同学都知道Nginx可以用来做负载均衡和反向代理,非常好用.做前后端分离也是非常的方便. 今天我 ...
随机推荐
- 解决teamviewer试用期到期的方法
Teamviewer是一款远程控制软件,使用过程中系统弹出“Teamviewer试用版已到期”的提示, 需要用户购买许可证或延长试用期才能继续使用,解决teamviewer试用期到期问题步骤如下: 出 ...
- Angular的启动过程
我们知道由命令 ng new project-name,cli将会创建一个基础的angular应用,我们是可以直接运行起来一个应用.这归功与cli已经给我们创建好了一个根模块AppModule,而根模 ...
- acm数论之旅--组合数(转载)
随笔 - 20 文章 - 0 评论 - 73 ACM数论之旅8---组合数(组合大法好(,,• ₃ •,,) ) 补充:全错排公式:https://blog.csdn.net/Carey_Lu/ ...
- sqlserver查询使用with(nolock)详解
所有Select加 With (NoLock)解决阻塞死锁 在查询语句中使用 NOLOCK 和 READPAST 处理一个数据库死锁的异常时候,其中一个建议就是使用 NOLOCK 或者 READPAS ...
- 多进程pipe
pipe模块可以实现进程之间数据传递 栗子1:3个进程,一个主进程,2个子进程,三个管道,三个进程通过3个管道连接,主进程发一个信息,通过2个子进程转发,最后回到主进程输出 import multip ...
- docker安装后启动报错
docker安装后启动不起来: 查看日志 /var/log/message 其中有一行为: Your kernel does not support cgroup memory limit ...
- Python学习(三)——Python的运算符和数值、字符的类中方法
Python开发IDE PyCharm,eclipse PyCharm的基础用法 全部选中后 Ctrl+?全部变为注释 运算符 结果为值的运算符 算术运算符: + - * / % // ** 赋值运算 ...
- Maven (一)--- 入门和依赖
部分图片来自参考资料 问题 : - maven 生命周期是怎么样的 - mvn clean install 与 mvn clean deploy 的区别是什么 概述 Maven 是一种构建项目的工具, ...
- C语言:对长度为7的字符串,除首尾字符外,将其余5个字符按ASCII降序排序。-计算并输出3~n之间所有素数的平方根之和。
//对长度为7的字符串,除首尾字符外,将其余5个字符按ASCII降序排序. #include <stdio.h> #include <ctype.h> #include < ...
- win10使用L2TP连接失败,报远程服务器未响应错误解决办法,亲测可用!
报错如下: 原因是L2TP连接需要IPSec加密,远程服务器未响应说明IPSec加密被禁用了,需要在注册表启用它,具体步骤如下: 1.以管理员账号身份打开CMD,win10 是 win+x键 2.找到 ...