对于大型请求正文,将忽略Nginx proxy_cache_key $ request_body [英] Nginx proxy_cache_key $request_body is ignored for large request body
问题描述
我使用nginx作为反向代理,我希望它能够缓存POST请求。我的后端已正确配置为POST请求返回适当的缓存控制头。在nginx中我配置了:
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";
这适用于小型HTTP POST请求。但是我开始注意到对于大型请求(例如文件上传),似乎 $ request_cache_key
中忽略了 $ request_body
。当包含文件上载的表单使用完全不同的数据提交两次时,nginx将返回缓存的结果。
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.
可能导致这种情况的原因是什么?如何在<$ c $中配置nginx以使用 $ request_body
(或 $ request_body
的哈希值) c> proxy_cache_key 即使是大型POST请求?
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?
推荐答案
事实证明,当<$ c时$ c> $ content_length> client_body_buffer_size ,
然后将请求正文写入文件,变量 $ request_body ==
。
另见 http://mailman.nginx.org/ pipermail / nginx / 2013-September / 040442.html
这篇关于对于大型请求正文,将忽略Nginx proxy_cache_key $ request_body的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!