nginx 的 content阶段的root指令与alias指令
2024-09-04 03:19:48
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
三个变量
request_filename :待访问文件的完整路径
document_root : 由URI和root/alis规则生成的文件夹路径
realpath_root:将document_root中的软连接等换成真实路径
[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/:!
最新文章
- 理解timestamp
- Python’s SQLAlchemy vs Other ORMs[转发 0]
- qsort C++ VS2013 leetcode
- php生成网页桌面快捷方式
- 【leetcode】Remove Linked List Elements(easy)
- 什么是bower
- VMware下安装CentOS6.5
- win10*64+vs2015+opencv3.0工程模板配置
- 图像旋转、伸缩的自写matlab实现
- WebFrom 小程序【条件查询与分页整合】
- Java之JSON操作(Jackson)
- anaconda3 安装opencv3.4.2 cuda9.2 mint19(ubuntu 18.04)
- vue 踩坑-事件修饰符
- hdu 1540 线段树
- hive sql 查询一张表的数据不在另一张表中
- 【NGINX】Windows配置
- jwt 的使用
- Python廖雪峰学习笔记——操作文件和目录
- WEB渗透测试基础工具
- exception http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
热门文章
- 多核 CPU 和多个 CPU 有何区别?
- 微信小程序--缓存,支持过期时间的二次开发封装
- python代码在linux终端中执行报错:Unable to init server: Could not connect: Connection refused
- jmeter 进行websocket数据帧过大导致code 1009
- Vue - 如何使用npm run build后的dist文件夹
- opencv python:轮廓发现
- 吴裕雄 python 机器学习——数据预处理流水线Pipeline模型
- centos610无桌面安装libreoffice
- DataGrid DataGridTextColumn 樣式
- SSIS部署后执行失败,无法将保护的XML节点解密