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可以用来做负载均衡和反向代理,非常好用.做前后端分离也是非常的方便. 今天我 ...
随机推荐
- pgspider http fdw http 相关的几个配置参数
http 请求时间配置 session 级别的 set http.timeout_msec = 10000; SELECT http_set_curlopt('CURLOPT_TIMEOUT', '1 ...
- 谷歌play上APK的下载
https://apkcombo.com/tw-hk/ 在google搜索 APK DOWNLAOD就有专门下载谷歌PLAY的APK的
- VS2017出现不存在从"CString"到"const char*"的适当转换函数
出现不存在从CStrign到const char*的转换,可以将项目属性的字符集设置从"使用Unicode字符集“转换为”使用多字字符集“. 点击”项目“----“属性”----“配置属性” ...
- Docker容器里配置计划任务 crontab(DaoCloud+Docker +Laravel5)
最近项目涉及到一个定时任务的功能,所以去这几天研究了一下 crontab 的使用方法,按照网上的相关教程顺利在自己的电脑上成功开启了这个功能 Laravel + crontab 添加 crontab ...
- HTML连载59-子绝父相
一.子绝父相 1.只使用相对定位,对图片的位置进行精准定位. <!DOCTYPE html> <html lang="en"> <head> & ...
- AI人工智能之基于OpenCV+face_recognition实现人脸识别
因近期公司项目需求,需要从监控视频里识别出人脸信息.OpenCV非常庞大,其中官方提供的人脸模型分类器也可以满足基本的人脸识别,当然我们也可以训练自己的人脸模型数据,但是从精确度和专业程度上讲Open ...
- python的爬虫小入门
爬虫的相关操作 1.爬文本内容 # coding=gbk import requests ##声明相关库 import re response=requests.get('http://duanziw ...
- TensorFlow:使用inception-v3实现各种图像识别
程序来自博客: # https://www.cnblogs.com/felixwang2/p/9190740.html上面这个博客是一些列的,所以可以从前往后逐一练习. # https://www.c ...
- RTU license
Right to Use (RTU) licensing is a model in which licenses are not tied to a unique device identifier ...
- 8,xhtml和html有什么区别
8,xhtml和html有什么区别 功能上有差别:xhtml可以兼容各大浏览器,手机,以及pda,浏览器也能快速准确地翻译网页 书写嘻惯的差别:xhtml必须正确的嵌套,闭合,区分大小写,文档必须有根 ...