Nginx的alias的用法及與root的區別

2021-08-14 13:52:25 字數 479 閱讀 3030

以前只知道nginx的location塊中的root用法,用起來總是感覺滿足不了自己的一些想法。然後終於發現了alias這個東西。

location /request_path/image/
這樣配置的結果就是當客戶端請求 /request_path/image/cat.png 的時候, 

nginx把請求對映為/local_path/image/request_path/image/cat.png

location /request_path/image/
這時候,當客戶端請求 /request_path/image/cat.png 的時候, 

nginx把請求對映為/local_path/image/cat.png

root是對映位址以後再加上本身的位址。

alias是直接請求對映的位址

Nginx的alias的用法及與root的區別

以前只知道nginx的location塊中的root用法,用起來總是感覺滿足不了自己的一些想法。然後終於發現了alias這個東西。location request path image 這樣配置的結果就是當客戶端請求 request path image cat.png 的時候,nginx把請求對映...

Nginx中root與alias的用法及區別

nginx中root與alias都是定義location 塊中虛擬目錄訪問的檔案位置 先看看兩者在用法上的區別 location img 若按照上述配置的話,當客戶端請求訪問 img 目錄裡面的檔案時,ningx會自動去 var www image 目錄找檔案 location img 若按照這種配...

nginx的root和alias用法

location test 當你訪問的是 test index.html 時 會返回主機位置 home angel test index.html location test 當你訪問的是 test index.html 時 會返回主機位置 home angel new index.html 一定要...