node.jsnginxfaviconcache-controlexpires-header

Adding Expires headers to favicon.ico using Nginx as proxy of node.js


My site is running on node.js and I'm using Nginx to server my static files from a cookieless domain. For these files I have setup Nginx to set the expires headers. However it does not seem to be working for my favicon.

My Nginx default config file:

# 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 has a minetype in mime.types:

image/x-icon    ico;

Service response headers showing no Cache-control or Expires:

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

And these are the response of a random image that has Cache-control and as Expires as you would expect:

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

I checked if the favicon was being served from the static domain (static.domain.com/favicon.ico) and not the websites document root (domain.com/favicon.ico). Does anyone have any idea what is wrong or how I could debug this?


Solution

  • Apparently there was another line matching the favicon, hidden in an include file, which I ommitted in the question for the sake of simplicity.

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

    Removing this (because there is favicon present on this site) solved my issue :-)