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

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
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;
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/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:

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.

Thanks. Let me try this out.