
4

root和alias的区别
source link: https://blog.51cto.com/wemux/5343652
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

root和alias的区别
alias 指定的目录是准确的,给location指定一个目录。
root 指定目录的上级目录,并且该上级目录要含有locatoin指定名称的同名目录。
以root方式设置资源路径:
语法: root path;
配置块: http、server、location、if
配置块: http、server、location、if
以alias 方式设置资源路径:
语法: alias path;
配置块: location
配置块: location
Example:
location /img/ {
alias /var/www/image/;
}
alias /var/www/image/;
}
#若按照上述配置的话,则访问/img/目录里面的文件时,ningx会自动去/var/www/image/目录找文件
location /img/ {
root /var/www/image;
}
root /var/www/image;
}
#若按照这种配置的话,则访问/img/目录下的文件时,nginx会去/var/www/image/img/目录下找文件
021/10/21 17:47:09 [error] 101161#101161: *970472 "/usr/share/nginx/image/image/index.html" is not found (2: No such file or directory), client: 192.168.10.1, server: _, request: "GET /foodsafety/ HTTP/1.1", host: "192.168.10.130"
错误日志查看
如果文件找不到,可以查看错误日志:logs/error.log,一般会告诉你nginx去哪个路径下找资源了,可以反查nginx.conf配置路径是否正确。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK