8

I'm setting up a Nginx server for a cache proxy server.

I've noticed that cache not working when this header is in request:

Pragma: no-cache

Without this header, cache working ok.

Can I make Nginx ignore this header field from client, and caching result. Because I can't change client code easily(need reinstalling lot of devices).

5
  • Honoring cache control settings is by design. They are part of the http protocol
    – HBruijn
    Nov 5, 2014 at 8:23
  • 1
    Yes but there's a fault in client design. May be I can try chain two nginx together and clean that header in first proxy :( Nov 5, 2014 at 8:37
  • Although as far as I know there is little use in caching client requests, only in the server response.
    – HBruijn
    Nov 5, 2014 at 8:41
  • Nginx does not honor headers asking uncached replies by default as it's a DoS vector. How do you test it? Nov 5, 2014 at 8:48
  • I did it! Setup two nginx A and B, A receive request, clear header and proxy to B, B enable proxy_cache.... Nov 5, 2014 at 10:59

2 Answers 2

5

You can specifically instruct nginx to ignore headers with:

proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_ignore_headers Cache-Control;

With these directives, an nginx proxy instance will ignore the headers sent by the upstream server and set its own headers for the client (depending on what you specify in the proxy response configuration).

3
  • Not sure about the quotes, it's the format shown in the docs. I don't use quotes, test either way.
    – Andres B
    Nov 8, 2014 at 22:30
  • 3
    This doesn't answer the question at all. OP is asking how to ignore the request Pragma header not upstream response headers.
    – Phil
    Feb 11, 2019 at 23:31
  • 2
    According to nginx.com/blog/nginx-caching-guide nginx does not honor the Pragma: no-cache header by default.
    – mmlb
    Aug 13, 2019 at 13:31
0

Bringing together all of the comments...

Nginx doesn't honour the pragma:no-cache request header by default since it may be a DoS vector. However, being able to circumvent the cache may be a useful feature you would like to enable.

Removing this line from your config will revert to the default nginx configuration of ignoring the Pragma header and always using the cache.

proxy_cache_bypass $http_pragma;

Add this line to your config if you want to honour the Pragma header and circumvent the cache.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .