Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am using nginx for my webserver. I am trying to set an expiry date or a maximum age in the HTTP headers for static resources but it doesnt work. This is what i am using;

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires 31536000s;
            add_header Pragma "public";
            add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
            add_header X-Powered-By "blablabla";
            log_not_found off;

What i am doing wrong? Google pagespeed still warn me to use Leverage browser caching.

share|improve this question
The section of configuration you have posted looks fine. Check which headers are actually set (e.g. using Firebug). If the expires and cache-control headers are not set then another location block (or some other factor) is overriding the configuration above. –  cyberx86 Nov 30 '11 at 14:42
I have looked at headers . It shows this; Date: Wed, 30 Nov 2011 14:53:52 GMT Server: libwww-perl-daemon/5.827 Connection: close Date: Wed, 30 Nov 2011 14:53:52 GMT Server: nginx Vary: Accept-Encoding Vary: Cookie Content-Length: 48895 Content-Type: text/html; charset=UTF-8 and there is no overriding. –  borannb Nov 30 '11 at 15:02
Well, the headers are not being set, which suggests that your location block is not being triggered. If you have other location blocks (e.g. location / ) it is possible that they take precedence over this one. See the Nginx Docs for the order in which location blocks are executed. Only one location block will be triggered per request. –  cyberx86 Nov 30 '11 at 15:27
ahh this is very odd. tried lots of things and it is not working =/ –  borannb Nov 30 '11 at 16:45
did you try to reload nginx configuration? –  BigSack Aug 15 '13 at 4:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.