Search code examples
ruby-on-railsasset-pipelineassetsfavicon

Rails 3.1 favicon.ico not being served


Despite being in the /public directory, if I visit http://site.example.com/favicon.ico I get the 404 page. Interestingly, if I try to visit http://site.example.com/500.html I also get the 404 page leading me to believe that /public files are not being served up at all. I am running Nginx with Unicorn. Are there any settings in Rails that would disable the serving of /public assets?

Edit My nginx config:

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;
  # }
}

I do have root :to => 'reports#index' in my routes, but I don't see how that could make a difference.

Solution I moved the line root /srv/ctr/current/public; to above keepalive_timeout 5;


Solution

  • Check your routes.rb to make sure you dont have a line such as

    root :to => "home#index"
    

    Also check Nginx.conf to make sure you have

    root /path/to/app/public;
    

    for your server / vhost.

    Dave