nginx的root和alias的使用区别
- root的使用
location ^~ /a/ {
root /www/root/html/;
}
如果一个请求的URI是/a/a.html时,web服务器将会返回服务器上的/www/root/html/a/a.html的文件。
- alias使用:
location ^~ /a/ {
alias /www/root/html/new_a/;
}
如果一个请求的URI是/a/a.html时,web服务器将会返回服务器上的/www/root/html/new_a/a.html的文件。
注意这里是new_a,因为alias会把location后面配置的路径丢弃掉,把当前匹配到的目录指向到指定的目录。
注意:
- 使用alias时,目录名后面一定要加"/"。
- alias在使用正则匹配时,必须捕捉要匹配的内容并在指定的内容处使用。
- alias只能位于location块中。(root可以不放在location中)