结论:
当配置文件中是root时,nginx会在root的路径后添加location的路径作为需要查找的网页文件的路径即/data/nginx/test
当配置文件中是alias时,nginx会直接去alias的路径下查找网页文件即/data/nginx
测试:
要访问的网页文件:
[root@www nginx]# pwd
/data/nginx
[root@www nginx]# cat index.html
this is alias for test
[root@www test]# pwd
/data/nginx/test
[root@www test]# cat index.html
this is root for test
配置文件:
[root@www conf.d]# vim test.conf
server {
listen 80;
server_name www.hyc.org;
#access_log logs/host.access.log main;
location /test {
root /data/nginx;
index index.html index.htm;
}
}
清理缓存后用浏览器访问www.hyc.org/test:
将以上配置文件test.conf中的root修改为alias:
[root@www conf.d]# vim test.conf
server {
listen 80;
server_name www.hyc.org;
#access_log logs/host.access.log main;
location /test {
alias /data/nginx;
index index.html index.htm;
}
}
重新加载nginx配置文件:
[root@www conf.d]# systemctl reload nginx
清理浏览器缓存后再次测试