Can proxy_cache gzip cached content?

Maxim Dounin mdounin at mdounin.ru
Sat Feb 18 23:31:05 UTC 2012


Hello!

On Sat, Feb 18, 2012 at 09:43:11PM +0100, Massimiliano Mirra wrote:

> About this:
> 
> 
> >             location /proxied-stuff {
> >                     proxy_set_header Accept-Encoding gzip;
> >                     proxy_cache_key "$scheme$host$request_uri";
> >                     proxy_cache_valid 2d;
> >                     proxy_cache myapp_cache;
> >                     proxy_pass http://127.0.0.1:85;
> >             }
> >
> 
> I was hoping that gunzip'ping for clients that don't support compression
> would be as simple as adding the following inside the above block:
> 
>         if ($http_accept_encoding !~* gzip) {
>                 gunzip on;
>         }
> 
> But when nginx configuration is reloaded, I get: "nginx: [emerg] "gunzip"
> directive is not allowed here".
> 
> I suppose I could rewrite the request to an internal location, then within
> that location's block re-set the proxy_cache_key accordingly. But perhaps
> there's an easier way?

Yes.  The easier way is to just write

     gunzip on;

It will gunzip responses for clients which don't support gzip (as per 
Accept-Encoding and gzip_http_version/gzip_proxied/gzip_disabled, 
i.e. the same checks as done for gzip and gzip_static). 

Maxim Dounin



More information about the nginx mailing list