2012-01-10 58 views
3

儘管在/public目錄,如果我訪問http://site.example.com/favicon.ico我得到404頁面。有趣的是,如果我嘗試訪問http://site.example.com/500.html,我也會收到404頁面,導致我認爲/public文件沒有被提供。我正在用Unicorn運行Nginx。 Rails中是否有任何設置會禁用/public資產?Rails 3.1 favicon.ico沒有服務

編輯 我的nginx的配置:

server { 
    listen 80; 
    client_max_body_size 4G; 
    server_name _; 

    keepalive_timeout 5; 

    # Location of our static files 
    location ~ ^/(assets)/ { 
    root /srv/ctr/current/public; 
    gzip_static on; # to serve pre-gzipped version 
    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; 

    # If you don't find the filename in the static files 
    # Then request it from the unicorn server 
    if (!-f $request_filename) { 
     proxy_pass http://app_server; 
     break; 
    } 
    } 

    # error_page 500 502 503 504 /500.html; 
    # location = /500.html { 
    # root /var/rails/testapp/public; 
    # } 
} 

我有我的路線root :to => 'reports#index',但我不明白怎麼會有所作爲。

解決方案 我感動行root /srv/ctr/current/public;以上keepalive_timeout 5;

+0

我無法證實的Rails 3.1,Nginx的和獨角獸無視我的圖標,404.html或500。 HTML(從我的公共目錄)。這是我的配置,檢查是否有任何區別:https://gist.github.com/1589113祝你好運:) – 2012-01-10 13:38:08

回答

1

檢查您的routes.rb以確保你沒有一個行如

root :to => "home#index" 

還要檢查Nginx.conf以確保你有

root /path/to/app/public; 

爲您的服務器/虛擬主機。

戴夫

+2

戴夫,你確定'root:to =>「home#index」'可能是一個源對於這個錯誤?我有這個聲明,它可以得到我的favicon等,但'root/path/to/app/public;'指令也是我的建議。 – 2012-01-10 13:58:35

+1

timbrandes,只是檢查,是的,即使在favicon等路線應該工作。這是一個同時作爲我們的項目是多牌,多公司,所以我有源取決於所使用的(不要問!) – detheridge02 2012-01-10 14:05:17

+1

@ detheridge02你可能要編輯的是第一部分的主機名的圖標一個指令的回答,就像被接受的那樣,它可能會誤導不閱讀評論的用戶! – asymmetric 2015-01-08 11:05:24

0

Rails, favicon.ico not found

配置您的nginx的.conf

vim /etc/nginx/conf.d/your_project.conf

server { 
    ...... 

    # static resource routing - both assets folder and favicon.ico 
    location ~* ^/assets/|favicon.ico { 
     # Per RFC2616 - 1 year maximum expiry 
      # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html 
      expires 1y; 
      add_header Cache-Control public; 

      # Some browsers still send conditional-GET requests if there's a 
      # Last-Modified header or an ETag header even if they haven't 
      # reached the expiry date sent in the Expires header. 
      add_header Last-Modified ""; 
      add_header ETag ""; 
      break; 
     } 
}