Nginx proxy_cache_key $ request_body is used for a large request body

I use nginx as a reverse proxy, and I would like it to cache POST requests. My backend server is configured correctly to return the appropriate cache control headers for POST requests. In nginx, I configured:

proxy_cache_methods POST; proxy_cache_key "$request_method$request_uri$request_body"; 

This is great for small HTTP POST requests. However, I began to notice that for large requests (for example, to download files) it seems that $request_body ignored in proxy_cache_key . When a form containing a file upload is submitted twice with completely different data, nginx will return a cached result.

What could be the reason for this? How to configure nginx to use $request_body (or the $request_body hash) in proxy_cache_key even for large POST requests?

+7
reverse-proxy nginx multipartform-data cache-control
source share
1 answer

So, it turns out that when $content_length > client_body_buffer_size , the request body is written to the file and the variable $request_body == "" .

See also http://mailman.nginx.org/pipermail/nginx/2013-September/040442.html

+9
source share

All Articles