proxy_cache_bypass and non-200 response
gk at leniwiec.biz
Tue Sep 26 16:15:11 UTC 2017
I think I found a bug or undocumented feature in nginx. Or it's just me being stupid.
I am debugging the following case:
1. I have an upstream that sometimes returns HTTP 200 and sometimes returns HTTP 401 and both codes are OK from my point of view. Both are returned with X-Accel-Expires allowing for caching.
2. I have an nginx caching proxy server that uses that upstream and caches the responses. It also changes 401 to 403 using error_page.
3. Now if there is cache MISS for the URL and upstream returns 401 it gets cached by nginx correctly.
4. But if there is already HTTP 200 response in the cache and the request bypasses the cache and the upstream returns 401, the cache seems to ignore 401 and keeps old HTTP 200 response.
This makes it impossible to re-cache HTTP 200 response with a newer (401 but still newer) response.
Possibly same problem applies to other non-200 responses but right now only 401 interests me.
I am not using any directives like proxy_cache_use_stale or similar. Only proxy_pass, proxy_cache and proxy_cache_bypass. I set proxy_cache_key to $remote_addr. I am using nginx version 1.12.1 from your Ubuntu xenial repository.
More information about the nginx