# Nginx post response doesn't get cached

**URL:** <https://www.ruby-forum.com/t/nginx-post-response-doesnt-get-cached/225327>\
**Category:** NGINX\
**Created:** [December 29, 2012, 6:47pm UTC](https://www.ruby-forum.com/t/nginx-post-response-doesnt-get-cached/225327 "2012-12-29T18:47:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [December 29, 2012, 6:47pm UTC](https://www.ruby-forum.com/t/nginx-post-response-doesnt-get-cached/225327/1 "2012-12-29T18:47:10Z")

</div>

I’m using an old version of nginx (0.8) on centos as reverse proxy for  
caching POST requests in front of two upstream servers.  
The servers are built for receiving post requests and returning media,  
sometimes 10 MB in size.

When the responses are small, nginx caches work fine. When I get a 2 MB  
response, nginx doesn’t cache the POST response.

I tried increasing proxy buffer size and busy buffer size but it had no  
effect, how do I cache large POST responses in nginx?

Posted at Nginx Forum:

> **[nginx post response doesn't get cached](https://forum.nginx.org/read.php?2,234567,234567#msg-234567)**
>
> I'm using an old version of nginx (0.8) on centos as reverse proxy for caching POST requests in front of two upstream servers. The servers are built for receiving post requests and returning media, sometimes 10 MB in size. When the responses are...

---

<div class="post-metadata">

**Author:** ![nurettin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@nurettin](https://www.ruby-forum.com/u/nurettin)\
**Post date:** [January 4, 2013, 4:48am UTC](https://www.ruby-forum.com/t/nginx-post-response-doesnt-get-cached/225327/2 "2013-01-04T04:48:03Z")

</div>

Hello!

On Sat, Dec 29, 2012 at 12:46:21PM -0500, nurettin wrote:

> I’m using an old version of nginx (0.8) on centos as reverse proxy for  
> caching POST requests in front of two upstream servers.  
> The servers are built for receiving post requests and returning media,  
> sometimes 10 MB in size.
> 
> When the responses are small, nginx caches work fine. When I get a 2 MB  
> response, nginx doesn’t cache the POST response.
> 
> I tried increasing proxy buffer size and busy buffer size but it had no  
> effect, how do I cache large POST responses in nginx?

Normally responses for POST requests are not cached (even if  
response indicates it is cacheable) as there is no good generic  
way to construct a cache key.

If you want nginx to cache responses to POST requests, you should  
instruct it to do so explicitly using the “proxy\_cache\_methods”  
directive, e.g.

```
proxy_cache_methods GET HEAD POST;

```

See [Module ngx\_http\_proxy\_module](http://nginx.org/r/proxy_cache_methods).

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![nurettin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@nurettin](https://www.ruby-forum.com/u/nurettin)\
**Post date:** [January 4, 2013, 7:54am UTC](https://www.ruby-forum.com/t/nginx-post-response-doesnt-get-cached/225327/3 "2013-01-04T07:54:23Z")

</div>

Hi Maxim D.!

The proxy already caches small post responses. My cache key is request  
uri  
and body. I just don’t know how to increase the buffer.

Posted at Nginx Forum:

> **[Re: nginx post response doesn't get cached](https://forum.nginx.org/read.php?2,234567,234681#msg-234681)**
>
> I'm using an old version of nginx (0.8) on centos as reverse proxy for caching POST requests in front of two upstream servers. The servers are built for receiving post requests and returning media, sometimes 10 MB in size. When the responses are...

---

<div class="post-metadata">

**Author:** ![nurettin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@nurettin](https://www.ruby-forum.com/u/nurettin)\
**Post date:** [January 4, 2013, 1:33pm UTC](https://www.ruby-forum.com/t/nginx-post-response-doesnt-get-cached/225327/4 "2013-01-04T13:33:12Z")

</div>

Hello!

On Fri, Jan 04, 2013 at 01:53:39AM -0500, nurettin wrote:

> Hi Maxim D.!
> 
> The proxy already caches small post responses. My cache key is request uri  
> and body. I just don’t know how to increase the buffer.

There are no buffers which influence request cacheability.  
Responses are either cached or not regardless of their size.

I would recommend you to check if max\_size= configured in  
proxy\_cache\_path (if any) is big enough to store responses you  
want to cache. If it is, you may want to produce debug log to  
investigate what goes on, see here for details

> **[A debugging log](http://nginx.org/en/docs/debugging_log.html)**

You may also want to upgrade to make sure you are not hitting some  
old bug. The 0.8.x branch is way too old.

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![nurettin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@nurettin](https://www.ruby-forum.com/u/nurettin)\
**Post date:** [January 8, 2013, 8:32pm UTC](https://www.ruby-forum.com/t/nginx-post-response-doesnt-get-cached/225327/5 "2013-01-08T20:32:11Z")

</div>

Hello!

On Tue, Jan 08, 2013 at 06:57:08AM -0500, nurettin wrote:

> I have debug on error.log, here’s the output:  
> code 0  
> 2013/01/08 13:51:20 [notice] 32764#0: signal 29 (SIGIO) received
> 
> I’m not sure what to do here.

Ah, ok, the error message logged suggests that you need to  
increase upstream buffer - it’s used to store cache header and  
it’s too small to hold your cache key with request body included.

The “increase upstream buffer size” wording is indeed not very  
helpful, it was made more specific in nginx 1.1.0+. In case of  
proxy, you have to increase proxy\_buffer\_size, see  
[Module ngx\_http\_proxy\_module](http://nginx.org/r/proxy_buffer_size).

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![nurettin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@nurettin](https://www.ruby-forum.com/u/nurettin)\
**Post date:** [January 12, 2013, 8:34am UTC](https://www.ruby-forum.com/t/nginx-post-response-doesnt-get-cached/225327/6 "2013-01-12T08:34:05Z")

</div>

Thanks a lot

```
    proxy_buffers 8 2m;
    proxy_buffer_size 10m;
    proxy_busy_buffers_size 10m;

```

Now the response gets cached properly.

Posted at Nginx Forum:

> **[Re: nginx post response doesn't get cached](https://forum.nginx.org/read.php?2,234567,234967#msg-234967)**
>
> I'm using an old version of nginx (0.8) on centos as reverse proxy for caching POST requests in front of two upstream servers. The servers are built for receiving post requests and returning media, sometimes 10 MB in size. When the responses are...

---

<div class="post-metadata">

**Author:** ![nurettin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@nurettin](https://www.ruby-forum.com/u/nurettin)\
**Post date:** [January 8, 2013, 12:57pm UTC](https://www.ruby-forum.com/t/nginx-post-response-doesnt-get-cached/225327/7 "2013-01-08T12:57:29Z")

</div>

Here’s the related configuration:

proxy\_cache\_path /var/www/cache levels=1:2 keys\_zone=kendi-cache:1000m  
max\_size=10000m;  
proxy\_cache\_key “$request\_uri|$request\_body”;

When I send small requests, nginx works great.  
When I send a large post request (long uri) I get these logs:

I have debug on error.log, here’s the output:

2013/01/08 13:50:25 [error] 32765#0: \*1 cache key too large, increase  
upstream buffer size 4096, client:…  
2013/01/08 13:51:01 [warn] 32765#0: \*1 an upstream response is buffered  
to a  
temporary file /var/www/cache/tmp/0000000001 while reading upstream,  
client:…  
2013/01/08 13:51:20 [notice] 300#0: http file cache: /var/www/cache  
0.000M,  
bsize: 4096  
2013/01/08 13:51:20 [notice] 32764#0: signal 17 (SIGCHLD) received  
2013/01/08 13:51:20 [notice] 32764#0: cache loader process 300 exited  
with  
code 0  
2013/01/08 13:51:20 [notice] 32764#0: signal 29 (SIGIO) received

I’m not sure what to do here.

Posted at Nginx Forum:

> **[Re: nginx post response doesn't get cached](https://forum.nginx.org/read.php?2,234567,234783#msg-234783)**
>
> I'm using an old version of nginx (0.8) on centos as reverse proxy for caching POST requests in front of two upstream servers. The servers are built for receiving post requests and returning media, sometimes 10 MB in size. When the responses are...
