3,【Nginx】location下的alias与root的用法

https://blog.csdn.net/u013948858/article/details/79459455

官网有教程(官网不会看,多喝六个核桃)
alias: http://nginx.org/en/docs/http/ngx_http_core_module.html#alias
root: http://nginx.org/en/docs/http/ngx_http_core_module.html#root

nginix指定文件路径有2种方式root和alias主要区别在于nginx如何解释location侯爱民的uri,这个会使俩者分别以不同的方式将请求映射到服务器文件上,说白了就是2者凭借文件路径的手段不一样。

root 用法

句法:   root path
默认:    root html;
语境:   http,server, location, if in location

例子:

location     ^~ /request_path/dirt/{
root  /local_path/dirt/;
}

当客户端请求 /request_path/image/file.ext的时候 ,Nginx把请求解析映射为/local_path/dirt/request_path/dirt/file.ext

alias的用法

句法: alias path
默认

示例

location       /request_path/dirt/
alias   /local_path/dirt/file/;

当客户端请求 /requet_path/dirt/file.ext 的时候,Nginx把请求映射为 /local_path/dirt/file/file.ext 注意这里是file目录,因为alias会把location 后面配置的路径丢弃掉(比如/request_path/dirt/one.html,到alias那里就剩下one.html了),到alias那里就只剩下one.html了),把当前匹配到的目录指向到指定的目录。
其他:
1,使用alias时,目录名后面一定要加 " /" ,不然不会认这个文件。
2,alias在适应正则匹配时,location后uri中捕捉到要匹配到的内容后,并在指定的alias规则内容处使用。
...
location ~^/users/(.+.(?:gif|jpe?g|png))1;
}
...
3,alias只能位于location块中,而root的权限不限于location。

总结:
只能说遇到问题,不是谁都能解决,但是没有解决不了的问题。

猜你喜欢

转载自blog.csdn.net/weixin_34416754/article/details/86958251
今日推荐