Nginx 配置靜態文件 404 問題

使用Nginx作訪問靜態資源的時候,配置以後訪問一直是  404。html

個人配置是nginx

location /dist {
            root /usr/local/nginx/html/dist;
            }htm

緣由:資源

root 配置的意思是,會在root配置的目錄後跟上URL,組成對應的文件路徑。
即個人訪問
http://localhost/dist/index.html
最終去尋找的文件路徑是
/usr/local/nginx/html/dist/dist/index.htmlio

正確的地址應該是配置

/usr/local/nginx/html/dist/index.htmldi

因此訪問返回 404文件

 

Nginx提供了另一個靜態路徑配置  : alias
alias與root區別
root響應的路徑:配置的路徑+完整訪問路徑(完整的location配置路徑+靜態文件)
alias響應的路徑:配置路徑+靜態文件(去除location中配置的路徑)ps

因此將配置修改爲 alias,index

location /dist {
            alias /usr/local/nginx/html/dist/;
            }

ps:

使用alias時目錄名後面必定要加「/」

相關文章
相關標籤/搜索