天天看點

Nginx:root與alias的差別

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的差别

繼續閱讀