# Caching issues with nginx as reverse-proxy

**URL:** <https://www.ruby-forum.com/t/caching-issues-with-nginx-as-reverse-proxy/244871>\
**Category:** NGINX\
**Created:** [June 30, 2016, 3:00am UTC](https://www.ruby-forum.com/t/caching-issues-with-nginx-as-reverse-proxy/244871 "2016-06-30T03:00:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [June 30, 2016, 3:00am UTC](https://www.ruby-forum.com/t/caching-issues-with-nginx-as-reverse-proxy/244871/1 "2016-06-30T03:00:19Z")

</div>

Hi,  
I am using nginx as a reverse proxy and using the proxy-cache, I use the  
request body as a cache key as shown below.

```
location ^~ /mycachepath {
    proxy_pass http://upstreamservers;
    proxy_buffers 8 32K;
    proxy_buffer_size 64K;
    proxy_cache proxy-cache;
    proxy_cache_key 

```

“$scheme$host$request\_uri|$request\_body”;  
proxy\_cache\_valid 200 1m;  
proxy\_cache\_methods POST GET;  
proxy\_ignore\_headers Cache-Control;  
add\_header X-Cache-Status $upstream\_cache\_status;  
}

However, I observe that smaller request bodies the cache works perfectly  
but  
if the request body gets too big then it will actually _always_ return  
the  
cached version. Does anyone have any idea what’s going on and if someone  
also has come across a similar issue ? There is nothing in the logs  
except  
for this statement - “[warn] 29768#0: \*2329 a client request body is  
buffered to a temporary file /var/cache/nginx/client\_temp/0000000009,”  
for a  
given request.  
Any help is much appreciated.

Thanks!

Posted at Nginx Forum:

> **[caching issues with nginx as reverse-proxy](https://forum.nginx.org/read.php?2,267961,267961#msg-267961)**
>
> Hi, I am using nginx as a reverse proxy and using the proxy-cache, I use the request body as a cache key as shown below. location ^~ /mycachepath { proxy\_pass http://upstreamservers; proxy\_buffers 8 32K;

---

<div class="post-metadata">

**Author:** ![blue.outrigger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9bd4f/32.png) [@blue.outrigger](https://www.ruby-forum.com/u/blue.outrigger)\
**Post date:** [June 30, 2016, 9:14am UTC](https://www.ruby-forum.com/t/caching-issues-with-nginx-as-reverse-proxy/244871/2 "2016-06-30T09:14:46Z")

</div>

On Wed, Jun 29, 2016 at 09:00:02PM -0400, blue.outrigger wrote:

Hi there,

> I am using nginx as a reverse proxy and using the proxy-cache, I use the  
> request body as a cache key as shown below.

> ```
> proxy_cache_key "$scheme$host$request_uri|$request_body";
> 
> ```

> **[$request\_body - Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_body)**
>
> The PROXY protocol must be previously enabled by setting the proxy\_protocol parameter in the listen directive.

If the request body was not read to a memory buffer, this variable is  
presumably empty (and therefore: the same for all requests).

> However, I observe that smaller request bodies the cache works perfectly but  
> if the request body gets too big then it will actually _always_ return the  
> cached version. Does anyone have any idea what’s going on and if someone  
> also has come across a similar issue ?

Set your client\_body\_buffer\_size big enough that it will hold the entire  
request, if you want to cache POSTs this way.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
