使用Nginx作为node.js的代理,将expires头添加到favicon.ico

时间:2012-12-11 23:28:57

标签: node.js nginx favicon cache-control expires-header

我的网站正在node.js上运行,而我正在使用Nginx从无cookie域中提供静态文件。对于这些文件,我设置了Nginx来设置expires头。然而,它似乎不适合我的favicon。

我的Nginx 默认配置文件:

# static content
server {
        server_name static.domain.com;
        root /my/website/lives/here/public;

        location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
            expires 365d;
        }
}

Ico在 mime.types 中有一个minetype:

image/x-icon    ico;

服务响应标头显示没有缓存控制或过期:

Accept-Ranges:bytes
Connection:keep-alive
Content-Length:32988
Content-Type:image/x-icon
Date:Tue, 11 Dec 2012 23:20:19 GMT
Last-Modified:Sat, 08 Dec 2012 11:51:28 GMT
Server:nginx/1.1.19

这些是随机图像的响应,它具有Cache-control和Expires,如你所料:

Cache-Control:max-age=31536000
Connection:keep-alive
Date:Tue, 11 Dec 2012 23:24:00 GMT
Expires:Wed, 11 Dec 2013 23:24:00 GMT
Last-Modified:Tue, 11 Dec 2012 23:04:24 GMT
Server:nginx/1.1.19

我检查了favicon是从静态域(static.domain.com/favicon.ico)提供的,而不是网站文档root(domain.com/favicon.ico)。有没有人知道什么是错的或我如何调试它?

1 个答案:

答案 0 :(得分:0)

显然还有另一条与favicon相匹配的行,隐藏在一个包含文件中,为了简单起见,我在问题中省略了这一行。

location = /favicon.ico {
    log_not_found   off;
    access_log  off;
}

删除此(因为此网站上有favicon)解决了我的问题: - )