1. 程式人生 > 實用技巧 >Nginx之偽404( root與alias )

Nginx之偽404( root與alias )

目錄

一、現象

二、root與alias的區別

三、建議

四、寫在最後

一、現象

人類善於偽裝,機器某些時候也善於偽裝;Nginx請求看到404,第一反應就是檔案不存在;但我們去檢查的時候,它就正兒八經的躺在裡面;既然存在,那為什麼要404呢?

二、root與alias

1、在Nginx的配置檔案中,可以使用root與alias指定工作目錄 root:指定專案的根目錄 alias:指定虛擬目錄 2、訪問的差別
location /demo/ {
    root /test/;
} 

當瀏覽器訪問:http://127.0.0.1/demo/index.html時,對映到伺服器上的檔案為:/test/demo/index.html

location /demo/ {
    alias /test/;
}

當瀏覽器訪問:http://127.0.0.1/demo/index.html時,對映到伺服器上的檔案為:/test/index.html

三、建議

1、在location /中配置root目錄; 2、在location /path中配置alias虛擬目錄

四、寫在最後

在平凡中堅持前行,總有一天會遇見不一樣的自己。 寫部落格記錄、思考、總結,趟過的坑不趟第二遍。 所有的文章,皆同步在公眾號“運維汪”,可關注;也可加入“不扯淡,專注於技術”的QQ群:753512236;