2013-02-21 168 views
0

我在nginx服務器配置中很新。我有一個問題,在公共目錄下的子目錄下提供文件。nginx和公共子目錄

例如,下的文件; rails_app/public/uploads/client/2/image/7 /目錄或rails_app/public/picture /目錄不在服務 但我沒有問題:rails_app/public/webcam.swf

就像某種方式子目錄是沒有服務。

我production.rb文件

# Disable Rails's static asset server (Apache or nginx will already do this) 
    config.serve_static_assets = false 

只有當我設置serve_static_assets到真正的我沒有問題

我nginx的配置:

upstream thin { 
    server '127.0.0.1:3000'; 
    server '127.0.0.1:3001'; 
    server '127.0.0.1:3002'; 
    server '127.0.0.1:3003'; 
    server '127.0.0.1:3004'; 
} 

server { 
    listen 80 default deferred; 
    # server_name example.com; 
    root /home/user/appname/public; 

    location ^~ /assets/ { 
    root /home/user/appname/public; 
    gzip_static on; 
    expires max; 
    add_header Cache-Control public; 
    } 

    location/{ 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_pass http://thin; 
    } 
    error_page 500 502 503 504 /500.html; 
    client_max_body_size 4G; 
    keepalive_timeout 10; 
} 

你可以幫我這個配置?

在此先感謝。

+1

你的配置是非常標準的。當您發出失敗的請求時,錯誤日誌中有什麼? – 2013-02-21 01:05:57

+0

這裏我得到了什麼:[21/Feb/2013:04:39:11 +0400]「GET /pictures/20-02-2013-09-55-37.jpg HTTP/1.1」404 446「 - 」「 Mozilla/5.0(X11; Linux x86_64)AppleWebKit/537.17(KHTML,如Gecko)Chrome/24.0.1312.69 Safari/537.17「 – 2013-02-21 01:32:40

回答

0

我認爲問題在於您的location /塊會捕獲您的動態請求以及您的非資產靜態請求。嘗試這個配置(注意try_files線):

server { 
    listen 80 default deferred; 
    # server_name example.com; 
    root /home/user/appname/public; 
    try_files $uri @app; 

    location ^~ /assets/ { 
    root /home/user/appname/public; 
    gzip_static on; 
    expires max; 
    add_header Cache-Control public; 
    } 

    location @app { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_pass http://thin; 
    } 
    error_page 500 502 503 504 /500.html; 
    client_max_body_size 4G; 
    keepalive_timeout 10; 
}