Nginx proxy_cache_key $request_body is ignored for large request body

后端 未结 2 991
栀梦
栀梦 2021-02-20 02:32

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

2条回答
  •  执念已碎
    2021-02-20 03:15

    Rather than using the $request_body within the proxy_cache_key, you may more simply use $content_length. Of course, it comes with its own limitation, but if you know which query you will receive, it can be also a very interesting workaround.

    proxy_cache_key "$scheme$request_method$host$request_uri$content_length";
    

    You may alternatively use $request_body as well to keep the desired behavior for smaller request payload:

    proxy_cache_key "$scheme$request_method$host$request_uri$request_body$content_length";
    

提交回复
热议问题