if-none-match with proxy_cache : properly set headers

kapouer nginx-forum at nginx.us
Thu May 30 10:41:50 UTC 2013

i struggled a little to get nginx to cache 304 responses from backend using
What happens when configuring proxy_cache is that 304 responses are not
happening because
nginx strips If-None-Match request headers. It is a workaround to prevent
the client from getting
an empty response event if he did not send If-None-Match in the header.
A better workaround can be :

proxy_cache_key $http_if_none_match$scheme$proxy_host$request_uri;

So that the cache sends 304 if the header is properly set, and 200 if it
Of course one has to kill the first workaround :

proxy_set_header If-None-Match $http_if_none_match;

and cache both responses :

proxy_cache_valid 200 304 1h;

Comments welcome.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,239689,239689#msg-239689

More information about the nginx mailing list