nginx 配置文件root 、alias的区别

449 阅读1分钟

location /admin {

root /usr/share/nginx/html;

index index.html index.htm;

try_files $uri $uri/ /admin/index.html;

}

在nginx.conf 文件中配置location 有前缀 /admin 使用root时

/usr/share/nginx/html 文件夹下需要有admin的文件夹,html以及网站静态资源需要放在/admin文件夹下

location /admin {

alias /usr/share/nginx/html;

index index.html index.htm;

try_files $uri $uri/ /admin/index.html;

}

在nginx.conf 文件中配置location 有前缀 /admin 使用alias时

html以及网站静态资源可以直接放在/usr/share/nginx/html 文件夹下不需要admin文件夹

当使用root 时 查找文件时会带上 location path 的路径去查找文件

当使用alias时查找文件不会带上location path 的路径去查找文件