I use nginx as a reverse proxy and I would like it to cache POST requests. My back-end is correctly configured to return appropriate cache-control headers for POST requests. In nginx I have configured:
proxy_cache_methods POST;
proxy_cache_key "$request_method$request_uri$request_body";
This works great for small HTTP POST requests. However I started noticing that for large requests (e.g. file uploads) it seems like the $request_body
is ignored in the proxy_cache_key
. When a form containing a file upload is submitted twice with completely different data, nginx will return the cached result.
What could cause this? How can I configure nginx to use the $request_body
(or a hash of $request_body
) in the proxy_cache_key
even for large POST requests?