在Nginx的server配置经常会遇到root与alias的配置
server {
listen 80;
server_name com.sxkj;
access_log logs/access.log ;
error_log logs/error.log;
location /home/ {
root /www/root/web/;
}
#location /home/ {
# alias /www/root/web/;
#}
}
root实例:
location /home/ {
root /www/root/web/;
}
如果一个请求的URI是/home/index.html时,web服务器将会返回服务器上的/www/root/web/home/index.html的文件。
alias实例:
location /home/ {
alias /www/root/web/;
}
可直接访问 /www/root/web/下的资源文件,如果下面有test.html
则访问路径 /home/test.html
如果一个请求的URI是/home/index.html时,web服务器将会返回服务器上的/www/root/web/index.html的文件。alias会把location后面配置的路径丢弃掉,把当前匹配到的目录指向到指定的目录。