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

2021-08-11 13:22:58 字數 560 閱讀 6821

以前只知道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就可以知道怎麼用了吧~~ :)

root的處理結果是:root路徑+location路徑

alias的處理結果是:使用alias路徑替換location路徑

還有乙個重要的區別是alias後面必須要用「/」結束,否則會找不到檔案的。。。而root則可有可無~~

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 一定要...