nginx文件路径配置(root|alias)
2024-10-19 20:27:41
nginx指定文件路径主要有两种方式:root|alias。
那么他们究竟有什么区别呢?
指令的使用方法和作用域:
[root]
语法:root path
默认值:root html
配置段:http、server、location、if
[alias]
语法:alias path
配置段:location
root与alias主要区别在于nginx如何解释location后面的uri,这会使两者分别以不同的方式将请求映射到服务器文件上。
root的处理结果是:root路径+location路径。
alias的处理结果是:alias路径替换location路径。
还有一个重要的点是alias后面必须要用"/"结束。
示例:
root:
location ^~ /html/ {
root /opt/;
}
如果一个请求的URI是/opt/index.html时,web服务器将会返回服务器上的/opt/html/index.html的文件。
alias:
location ^~ /html/ {
alias /opt/;
}
如果一个请求的URI是/html/index.html时,web服务器将会返回服务器上的/opt/index.html的文件。因为alias会把location后面配置的路径丢弃掉,把当前匹配到的目录指向到指定的目录。
注意:
1. 使用alias时,目录名后面一定要加"/"。
2. alias在使用正则匹配时,必须捕捉要匹配的内容并在指定的内容处使用。
3. alias只能位于location块中。
4.root|alias不能作用于/tmp目录。
最新文章
- C#中的线程(一)入门
- PHP从mysql获取数据的方法
- Windows Azure Virtual Network (7) 设置Azure Virtual Machine固定公网IP (Virtual IP Address, VIP) (2)
- 自定义底部工具栏及顶部工具栏和Fragment配合使用demo
- poj2385 dp(递推)
- 初探Django线程发送邮件
- PHP 中级内容
- phpstorm 2017.3.3的安装和破解
- [HEOI2016]排序
- Aptana下Django1.6以后的项目模板结构改造
- T-1-java语言基础
- 2017-2018-2 20165231 实验三 敏捷开发与XP实践
- java.lang.NullPointerException 	at java.lang.ProcessBuilder.start(Unknown Source) 	at org.apache.hadoop.util.Shell.runCommand(Shell.java:482)
- 设计模式之迭代器模式(Iterator)
- 将远程git仓库里的指定分支拉取到本地(本地不存在的分支
- grafana----alert
- 相对熵(KL散度)
- Python做web开发,推荐几个能立马上手的小项目
- 后台线程下的WinFrom窗体控件操作 Invoke
- KindEditor的简单使用,以及上传图片预览图片,用户删除图片后的数据处理(重点),以及 BeautifulSoup,shutil两模块了解
热门文章
- 【leetcode】1275. Find Winner on a Tic Tac Toe Game
- MVVM(使用Prism框架)开发WPF
- Neko Performs Cat Furrier Transform CodeForces - 1152B 二进制思维题
- HZOJ 20190722 visit (组合数学+数论)
- ftell函数
- 应用程序无法正常启动(0xc000007b)请单击确定关闭程序
- LeetCode 73. 矩阵置零(Set Matrix Zeroes)
- 小程序web-view利用url给内嵌的网页传值
- excel中如何设置只打印第一页
- Python3并发写文件