cache gzipped content with proxy_pass

Maxim Dounin mdounin at
Mon Aug 16 18:48:01 MSD 2010


On Mon, Aug 16, 2010 at 08:56:47AM -0400, chrisl wrote:

> AFAIK nginx only stores plain (uncompressed) content when acting as a
> caching proxy server.

Not really.  nginx caches what upstream server sent to it.  If 
response was compressed by upstream server - it will cache 
compressed response.

> With gzip=on, content for gzip-accepting clients
> will be compressed by the server _for_ _every_ _request_ (?).

Yes - unless upstream server already returned precompressed 

> Wouldn't it be better to have two cache files like this:
> /data/nginx/cache/c29b7f54b2df7773722d382f4809d65029c
> /data/nginx/cache/c29b7f54b2df7773722d382f4809d65029c.gz

You may want to follow this thread:

It is believed that separate gzip cache is better idea.

> Another solution would be to add the internal variable gzip_ok to the
> config variable space. Then one could add this variable to
> proxy_cache_key:
>  proxy_cache_key "...:$gzip_ok:..."
> Currently I've added http_accept_enconding to the cache key, but since
> there are hundreds of different permutations for the value this is not
> an optimal solution.

The problem is that nginx itself and upstream server may have 
different ideas on what may be compressed.  And you need 
upstream's one here, not nginx's one.  Though probably it's 
a good idea to expose nginx's one anyway.

Maxim Dounin

More information about the nginx mailing list