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可以用来做负载均衡和反向代理,非常好用.做前后端分离也是非常的方便. 今天我 ...
随机推荐
- PHP中使用CURL实现Get和Post请求方法
1.cURL介绍 cURL 是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 cURL 库.本文将介绍 cURL的一些高级特性, ...
- mongodb的一些操作
插入: db.inventory.insert( { _id: 10, type: "misc", item: "card", qty: 15 } ) db.i ...
- Fiddler修改http请求响应简单实例
Fiddler是一个http调试代理,它能够记录并检查所有你的电脑和互联网之间的http通讯. 主要功能 设置断点,查看Fiddle说有的进出的数据(指cookie,html,js,css等文件,这些 ...
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.
关于以上错误,观察是否缺少了某一项,还要注意书写的顺序 建议这一类配置文件直接复制就好了,不要自己写 <?xml version="1.0" encoding="U ...
- wordpress 修改默认分页条数
哎,终于快做完了,今天弄了弄分页,真是网上扒的模板太高级了,把分页和导航的css和js冲突了,终于解决了, 然后有一个模板是三和一排显示的,其他的是单挑显示的,它默认10条,我寻思改成9条,找了半天, ...
- java平衡二叉树AVL数
平衡二叉树(Balanced Binary Tree)具有以下性质:它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树 右旋:在插入二叉树的时候,根节点的右侧高 ...
- 【PAT甲级】1085 Perfect Sequence (25 分)
题意: 输入两个正整数N和P(N<=1e5,P<=1e9),接着输入N个正整数.输出一组数的最大个数使得其中最大的数不超过最小的数P倍. trick: 测试点5会爆int,因为P太大了.. ...
- 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)
题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...
- phpstorm 断点调试
1.设置php的xdebug 在php.ini中设置 [XDebug] xdebug.profiler_output_dir="H:\phystudy\PHPTutorial\tmp\xde ...
- laravel qq邮件配置