From: http://stackoverflow.com/questions/10631933/nginx-static-file-serving-confusion-with-root-alias
一句話概括,root對(duì)應(yīng)的目錄會(huì)加上location部分去找文件,而alias則不會(huì)
location /static/ {
root /var/www/app/static/;
autoindex off;
}
如果我們這么寫(xiě),那么訪問(wèn)static目錄下的a.jpg就會(huì)去找/var/www/app/static/static目錄下的a.jpg,如果沒(méi)有這個(gè)static/static就會(huì)404
解決方法有兩種:
如果location中的static就是真實(shí)目錄,root中就不要寫(xiě)static了
location /static/ {
root /var/www/app/;
autoindex off;
}
或者用alias就不會(huì)再加上location的部分:
location /static/ {
alias /var/www/app/static/;
autoindex off;
}