博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx配置 -- 让匹配路径不作为文件目录的一部分
阅读量:4185 次
发布时间:2019-05-26

本文共 659 字,大约阅读时间需要 2 分钟。

转自: https://blog.csdn.net/u011510825/article/details/50531864

指定文件路径有两种方式root和alias,ot与alias主要区别在于nginx如何解释location后面的uri,这会使两者分别以不同的方式将请求映射到服务器文件上。

[root]

语法:root path
默认值:root html
配置段:http、server、location、if

[alias]

语法:alias path
配置段:location

root实例:
 
location ^~ /t/ {     root /www/root/html/;}
如果一个请求的URI是/t/a.html时,web服务器将会返回服务器上的/www/root/html/t/a.html的文件。

alias实例:

location ^~ /t/ {

alias /www/root/html/new_t/;}
如果一个请求的URI是/t/a.html时,web服务器将会返回服务器上的/www/root/html/new_t/a.html的文件。注意这里是new_t,因为alias会把location后面配置的路径丢弃掉,把当前匹配到的目录指向到指定的目录。

注意:

1. 使用alias时,目录名后面一定要加"/"。
3. alias在使用正则匹配时,必须捕捉要匹配的内容并在指定的内容处使用。
4. alias只能位于location块中。(root可以不放在location中)

你可能感兴趣的文章