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 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;
    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 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
link|improve this question

56% accept rate
feedback

2 Answers

Is this behaviour visible with a web browser or only curl? Because I don't think curl will deflate by default, hence you getting binary data. Try the following:

curl -I -H 'Accept-Encoding: gzip,deflate' www.site.com/cs
link|improve this answer
feedback

I believe the cached assets are getting corrupted which is why the requests that bypass the cache (X-Cache-Status: MISS) are fine. Responses from requests that bypass the cache can still be cached. I don't know what conditions you're using for bypassing the cache, but when I encountered this problem it had something to do with responses for authenticated users being cached and then that cache being served to unauthenticated users.

If you add a proxy_no_cache $http_cs directive I suspect that will solve it... but of course not caching bypassed requests may be undesired behavior.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.