nginx root 与 alias 的区别
前言
nginx 的 root、alias 用来指定文件路径,区别如下
root
语法:root path
默认值:root html
配置段:http、server、location、if
root会根据完整的URI请求来映射,root + location 后面配置的路径
root结尾可以是/,也可以不是/
示例:
访问:/demo/index.html
指向文件:/usr/local/nginx/rootDemo/demo/index.html
location /demo/ {
root /usr/local/nginx/rootDemo;
}
alias
语法:alias path
配置段:location
alias会把 location 后面配置的路径丢弃掉,把当前匹配到的目录指向到指定的目录
alias必须以/结尾
示例:
访问:/demo/index.html
指向文件:/usr/local/nginx/aliasDemo/index.html
location /demo/ {
alias /usr/local/nginx/aliasDemo/;
}
正文到此结束