【问题标题】:Adding Expires headers to favicon.ico using Nginx as proxy of node.js使用 Nginx 作为 node.js 的代理将 Expires 标头添加到 favicon.ico
【发布时间】:2012-12-11 23:28:56
【问题描述】:

我的网站在 node.js 上运行,我正在使用 Nginx 从无 cookie 的域中提供我的静态文件。对于这些文件,我设置了 Nginx 来设置过期标头。但是,它似乎不适用于我的网站图标。

我的 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: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

我检查了网站图标是否是从静态域 (static.domain.com/favicon.ico) 而非网站文档根 (domain.com/favicon.ico) 提供的。有谁知道出了什么问题或我该如何调试?

【问题讨论】:

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


    【解决方案1】:

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

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

    删除这个(因为这个网站上有网站图标)解决了我的问题:-)

    【讨论】:

    • 如果您在网站上展示了 favicon.ico,则与此无关。如果找不到图标,这只会禁用 access_log 和 error_log...
    猜你喜欢
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 2021-09-15
    相关资源
    最近更新 更多