Ruby on rails 未提供Rails 3.1 favicon.ico
尽管在Ruby on rails 未提供Rails 3.1 favicon.ico,ruby-on-rails,asset-pipeline,assets,favicon,Ruby On Rails,Asset Pipeline,Assets,Favicon,尽管在/public目录中,如果我访问http://site.example.com/favicon.ico我得到了404页。有趣的是,如果我尝试访问http://site.example.com/500.html我还得到了404页,这让我相信,/public文件根本没有被提供。我在用独角兽运行Nginx。Rails中是否有任何设置会禁用/public资产的服务 编辑 我的nginx配置: server { listen 80; client_max_body_size 4G; se
/public
目录中,如果我访问http://site.example.com/favicon.ico
我得到了404页。有趣的是,如果我尝试访问http://site.example.com/500.html
我还得到了404页,这让我相信,/public
文件根本没有被提供。我在用独角兽运行Nginx。Rails中是否有任何设置会禁用/public
资产的服务
编辑
我的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代码>以上保持激活超时5代码>检查您的routes.rb,确保您没有诸如
root :to => "home#index"
还要检查Nginx.conf以确保
root /path/to/app/public;
对于您的服务器/vhost
戴夫
配置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;
}
}
我无法确认Rails 3.1、Nginx和Unicorn是否忽略了我的favicon、404.html或500.html(来自我的公共目录)。这是我的配置,用于检查是否存在任何差异:祝你好运:)Dave,你确定root:to=>“home#index”
可能是此错误的来源吗?我有那个声明,它可以得到我的favicon等,但是根/path/to/app/public代码>指令也是我的建议。timbrandes,刚刚检查过,是的,即使在favicon等的路线也应该有效。由于我们的项目是多许可证、多公司的,所以我有一个指令,根据使用的主机名(不要问!!)来获取favicon@detheridge02您可能想编辑您答案的第一部分,因为被接受可能会误导不阅读评论的用户!