# Nginx cached page returning binary data(.gz file) every now and then. Works when cached folder is de

**URL:** <https://www.ruby-forum.com/t/nginx-cached-page-returning-binary-data-gz-file-every-now-and-then-works-when-cached-folder-is-de/215253>\
**Category:** NGINX\
**Created:** [December 28, 2011, 4:15pm UTC](https://www.ruby-forum.com/t/nginx-cached-page-returning-binary-data-gz-file-every-now-and-then-works-when-cached-folder-is-de/215253 "2011-12-28T16:15:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [December 28, 2011, 4:15pm UTC](https://www.ruby-forum.com/t/nginx-cached-page-returning-binary-data-gz-file-every-now-and-then-works-when-cached-folder-is-de/215253/1 "2011-12-28T16:15:12Z")

</div>

I have an nginx server running as a proxy. A page from it is  
configured to be cached and served compressed.  
But then every now and then it serves the page as .gz file which shows  
as up a file to be downloaded. A curl –I hit returns binary data.  
curl -I [Custom Application Development Software for Business - Salesforce.com](http://www.site.com/cs)  
But when I deleted the cache folder everything starts working fine.  
sudo rm -r /tmp/nginx/cscache/  
What could be wrong? Can someone help?

This is the config  
location = /cs {  
proxy\_pass [http://localhost:82](http://localhost:82);  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_ignore\_headers Set-Cookie;  
proxy\_ignore\_headers Cache-Control;  
proxy\_ignore\_headers Expires;  
proxy\_ignore\_headers X-Accel-Expires;  
add\_header X-Cache-Status $upstream\_cache\_status;  
proxy\_cache cscache;  
proxy\_cache\_bypass $http\_cs;  
proxy\_cache\_key $request\_uri;  
proxy\_cache\_valid 200 302 1d;  
proxy\_cache\_valid 404 1m;  
proxy\_cache\_use\_stale error timeout invalid\_header;  
}  
And the result during a valid curl -I call.

[c@c ~]$ curl -I [Custom Application Development Software for Business - Salesforce.com](http://www.site.com/cs)  
HTTP/1.1 200 OK  
Server: nginx  
Date: Wed, 28 Dec 2011 14:49:39 GMT  
Content-Type: text/html; charset=utf-8  
Connection: keep-alive  
Keep-Alive: timeout=60  
Vary: Accept-Encoding  
Vary: Cookie,Accept-Encoding  
X-Mod-Pagespeed: 0.9.17.7-716  
Cache-Control: max-age=0, no-cache, no-store  
X-Cache-Status: MISS

Cross Posted:

> <https://serverfault.com/questions/344705/nginx-cached-page-returning-binary-data-gz-file-every-now-and-then-works-when>

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [December 28, 2011, 4:48pm UTC](https://www.ruby-forum.com/t/nginx-cached-page-returning-binary-data-gz-file-every-now-and-then-works-when-cached-folder-is-de/215253/2 "2011-12-28T16:48:34Z")

</div>

Hello!

On Wed, Dec 28, 2011 at 08:44:07PM +0530, Quintin P. wrote:

> location = /cs {  
> proxy\_cache\_key $request\_uri;  
> proxy\_cache\_valid 200 302 1d;  
> proxy\_cache\_valid 404 1m;  
> proxy\_cache\_use\_stale error timeout invalid\_header;  
> }

Most likely your backend gzips responses (if client supports  
gzipp), and these are getting cached.

Possible solutions include disabling gzipping on backend or  
clearing Accept-Encoding header on nginx side before passing  
request to backend, i.e.

```
proxy_set_header Accept-Encoding "";

```

Maxim D.

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [December 28, 2011, 5:13pm UTC](https://www.ruby-forum.com/t/nginx-cached-page-returning-binary-data-gz-file-every-now-and-then-works-when-cached-folder-is-de/215253/3 "2011-12-28T17:13:18Z")

</div>

Thanks. Let me try this out.
