Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using php-fpm with nginx as http server (I don't know much about reverse proxies, I just installed it and didn't touch anything), without Apache nor Varnish.

I need nginx to understand and honor the http headers I send. I tried with this config (taken from the docs) but didn't work:


fastcgi_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=website:10m inactive=10m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";


server {
    fastcgi_cache website;
    #fastcgi_cache_valid 200 302 1h;
    #fastcgi_cache_valid 301     1d;
    #fastcgi_cache_valid any     1m;
    #fastcgi_cache_min_uses 1;
    #fastcgi_cache_use_stale error timeout invalid_header http_503;
    add_header X-Cache $upstream_cache_status;

I always get "MISS" and the cache dir is empty. If I uncomment the other directives, I get hit, but I don't want those "dumb" settings, I need to control them within my backend. For example, if my backend says "public, s-maxage=10", the cache should be considered stale after 10 secs. Instead, nginx will store it for 1h, because of these directives.

I was thinking whether I should try proxy_cache, not sure what's the difference. In both fastcgi and proxy modules docs it says this:

The cache honors backend's Cache-Control, Expires, and etc.
since version 0.7.48, Cache-Control: private and no-store only
since 0.7.66, though. Vary handling is not implemented.

nginx version: nginx/1.1.19

Any thoughts?

pd: I also have the reverse proxy that is offered by Symfony2 (which I turn off to use nginx's). The headers are interpreted correctly by it, so I think I'm doing it right.

share|improve this question
up vote 0 down vote accepted

Apparently nginx does not recognize this header: Cache-Control: public, s-maxage=10. I tried with maxage and worked fine.

I wonder if the other caches will work (ETag, Last Modified, etc)...

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.