Nginx does not return 304 for "if-modified-since" header Nginx does not return 304 for "if-modified-since" header curl curl

Nginx does not return 304 for "if-modified-since" header


In order for the backend application server https://example.com to generate 304 responses it will need to see the If-Modified-Since request header. In your case that header is getting to nginx but not to the application server. You need to tell nginx to pass it through. Add the following to your location block:

proxy_set_header If-Modified-Since $http_if_modified_since;

Remove if_modified_since before and add_header Last-modified. Those lines are not helpful because Last-Modified needs to be generated by the application server, rather than by your nginx proxy.

It may be possible for the nginx proxy to take charge of whether to send 304, by unconditionally querying the application server (and doing all the work entailed in generating a response) and then deciding whether to send 304, rather than passing on the full response (probably code 200), based on the Last-Modified header in that response, but I can't see any benefit from doing it that way.

The answers given to another question helped me to realise how little the nginx proxy knows about the freshness of dynamic content that it is proxying.