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 have a page in nginx as follows

location = /page {
    proxy_pass http://localhost:82;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_hide_header Set-Cookie;
    access_log off;
    add_header Cache-Control public;
    add_header X-Cache-Status $upstream_cache_status
    proxy_cache             page;
    proxy_cache_key         backend$request_uri;
    proxy_cache_valid       200 302 100d;
    proxy_cache_valid       404      1m;
    proxy_cache_use_stale   error timeout invalid_header;

With the cache setting as follows

proxy_cache_path  /tmp/nginx/cache  levels=1:2 keys_zone=page:10m inactive=7d  max_size=50m;

But this page always returns a miss

enter image description here

What could be wrong?

share|improve this question
up vote 7 down vote accepted

If your backend responses have a Set-Cookie header, you need proxy_ignore_headers Set-Cookie; instead of proxy_hide_header Set-Cookie;

share|improve this answer
Could you please explain the downvote? OP has proxy_hide_header Set-Cookie, so it wouldn't appear in the response headers sent back to the client even if the upstream sets it, but afaict, unless you tell nginx to actually ignore the header, it will still mark the response as not cacheable. – kolbyjack Nov 1 '11 at 13:19
It didnt fix the problem.. – Quintin Par Nov 1 '11 at 15:45
Is there anything in the error log? You could also try telling nginx to ignore Cache-Control, but it should be handling that properly. – kolbyjack Nov 1 '11 at 16:02
This answer actually works and is also found on Nginx forum. More here: – Hieu Nov 17 '15 at 8:35

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.