Question

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;

Was it helpful?

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

OTHER TIPS

Rails, favicon.ico not found

Configure your 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;
      }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top