2012-08-12 67 views
2

我通過nginx的努力服務器靜態內容在我的Node.js應用程序。對於看似簡單明顯的設置,我無法通過nginx路由靜態內容。有了這條線:的Node.js:Nginx的不會提供靜態內容

location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ { 
        access_log off; 
        expires max; 
    } 

nginx的不服務器上的任何靜態內容(JS,CSS,圖像) - 但除去該我看到靜態內容顯示。 在Node方面,我使用express和jade。

nginx.conf: https://gist.github.com/3331669

默認: https://gist.github.com/3331674

回答

2

嘗試以下操作:

location ~ \.(jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ { 
    access_log off; 
    expires max; 
} 
+0

沒有運氣。有一件事是我運行nginx作爲www-data用戶,而我的應用程序的權限是root:root - 是否導致這種情況?如果我用'root'運行nginx,事情就可以正常工作。以root身份運行nginx是否有問題? – Ved 2012-08-13 05:30:05

+0

以root身份運行事情是一個糟糕的主意,除非他們真的必須這樣做。將這些靜態文件的八進制權限設置爲644(即可由其他人讀取),以便www數據用戶可以讀取它們。 – matzahboy 2012-08-13 08:23:24

+0

如果運行物爲根,在您的應用程序就可以摧毀你的服務器上存在漏洞(因爲該漏洞會以root權限運行) – matzahboy 2012-08-13 21:14:10

0

請嘗試以下

location ~* .*\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html?)$ { 
    access_log off; 
    expires max; 
} 
+0

還是同樣的問題後,我從明確禁止的資產。 – Ved 2012-08-12 19:03:40

0

嘗試

location ~* .*\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ { 
     access_log off; 
     expires max; 
     root /var/www/yoursitename/public; 
    }