root目录:

root路径 + location路径

alias别名:

alias路径 替换 location路径

例:

location ^~ /dir/ {
    root /www/root/html/;
    # location = /www/root/html/ + /dir/
}
# 请求的URI: /dir/a.html时,返回 /www/root/html/dir/a.html


location ^~ /dir/ {
    alias /www/root/html/;
    # location = /www/root/html/
}
# 请求的URI:/dir/a.html时,返回:/www/root/html/a.html

注意
alias后面必须要用“/”结束,否则会找不到文件,root可有可无。
alias在使用正则匹配时,必须捕捉要匹配的内容并在指定的内容处使用。
alias只能位于location块中。(root可以不放在location中)

^~ 如果路径匹配那么不测试正则表达式

参考
nginx中的root与alias的差别