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).

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
user3368344
  • 81
  • 1
  • 1
  • 2
  • Honoring cache control settings is by design. They are part of the http [protocol](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) – HBruijn Nov 05 '14 at 08: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 :( – user3368344 Nov 05 '14 at 08:37
  • Although as far as I know there is little use in caching **client requests**, only in the server response. – HBruijn Nov 05 '14 at 08:41
  • Nginx does not honor headers asking uncached replies by default as it's a DoS vector. How do you test it? – Xavier Lucas Nov 05 '14 at 08:48
  • I did it! Setup two nginx A and B, A receive request, clear header and proxy to B, B enable proxy_cache.... – user3368344 Nov 05 '14 at 10:59

2 Answers2

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).

igracia
  • 103
  • 3
Andres B
  • 119
  • 6
  • Not sure about the quotes, it's the format shown in the docs. I don't use quotes, test either way. – Andres B Nov 08 '14 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 '19 at 23:31
  • 2
    According to https://www.nginx.com/blog/nginx-caching-guide/ nginx does not honor the `Pragma: no-cache` header by default. – mmlb Aug 13 '19 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.

Phil
  • 157
  • 7