nginx root 和 alias 配置區別
nginx指定文件路徑有兩種方式root和alias。root與alias主要區別在於nginx如何解釋location後面的uri,這會使兩者分別以不同的方式將請求映射到服務器文件上。
[root]
語法:root path
默認值:root html
配置段:http、server、location、if
[alias]
語法:alias path
配置段:location
實例:
目錄結構:
/var/nginx/html/
location /a {
root /var/nginx/html;
index a.html;
}
訪問到的文件是: /var/nginx/html/a/index.html
路徑是由三段拼接成的: /var/nginx/html + /a + index.html ; 路徑中間的 / 會自動處理.
最終訪問文件的目錄是: root 配置的路徑 + location 中的路徑
location /a {
alias /var/nginx/html/a;
index a.html;
}
訪問到的文件是: /var/nginx/html/index.html
路徑是由兩段拼接成的: /var/nginx/html/a + index.html ; 路徑中間的 / 會自動處理.
最終訪問文件的目錄是: alias 配置的路徑