Question

En dépit d'être dans le répertoire /public, si je visite http://site.example.com/favicon.ico je reçois la page 404. Fait intéressant, si j'essaie de visiter http://site.example.com/500.html Je reçois aussi la page 404 me porte à croire que les fichiers /public ne sont pas servis du tout. Je courais Nginx avec Unicorn. Y a-t-il des paramètres Rails qui désactiverait le service des actifs /public?

Modifier Ma config 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;
  # }
}

Je n'ai root :to => 'reports#index' dans mes voies, mais je ne vois pas comment cela pourrait faire une différence.

Solution Je me suis déplacé à la ligne root /srv/ctr/current/public; keepalive_timeout 5; ci-dessus

Était-ce utile?

La solution

Vérifiez votre routes.rb pour vous assurer que vous n'avez pas une ligne telle que

root :to => "home#index"

Vérifiez également nginx.conf pour vous assurer que vous avez

root /path/to/app/public;

pour votre serveur / vhost.

Dave

Autres conseils

??Rails, Favicon.ico pas trouvé

Configurer votre 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;
      }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top