这很奇怪,我一直在接受:
ActionController::RoutingError (No route matches "/favicon.ico")
但是我的公共目录中有favicon.ico
...任何想法如何解决这个问题? Nginx根本不会抛出错误。
答案 0 :(得分:11)
似乎nginx不处理您的静态资产(因为此静态文件请求转到ActionController)。检查nginx配置文件nginx.conf
中的公共根目录。
以下是Capistrano部署的示例:
server {
listen 80;
root /var/www/my_project/current/public;
}
你在头脑中使用了favicon_link_tag
助手吗?
答案 1 :(得分:10)
如果你想保持config.serve_static_assets = false,如果你有nginx或apache,建议你这样做,你可以告诉nginx直接静态地提供文件。出于性能原因,这一点尤其重要,因为您不希望rails提供这些资产。
下面是一个示例,它也正确地将nginx静态地提供给资产目录:
server {
listen 80;
root /var/www/my_project/current/public;
location / {
proxy_pass http://mysite;
proxy_redirect off;
proxy_set_header X_FORWARDED_PROTO https;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
# 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;
}
}
答案 2 :(得分:5)
确保favicon.ico
文件不为空(字节大小> 0)。出于某种原因,我有一个空的favicon.ico文件,它触发了相同的错误,即使该文件确实存在。
答案 3 :(得分:1)
在favicon.ico之前删除斜杠符号并尝试使用类似:
<link rel="shortcut icon" type="image/png" href="favicon.ico" />
答案 4 :(得分:1)
当我第一次从git存储库克隆代码并使用RAILS_ENV=production
运行时,我遇到了同样的问题。由于我的git存储库中没有assets目录,因此我需要运行rake assets:precompile
。
此外,我使用rails运行,因此config.serve_static_assets = true
工作。谢谢@Jiemurat