Can proxy_cache gzip cached content?

Massimiliano Mirra hyperstruct at gmail.com
Tue Feb 14 20:02:35 UTC 2012


Thanks for the pointers. As I wrote, I'd rather avoid gzipping in the
backend, but if that's the only option so be it.

I was also concerned about caching gzipped content using the value of
Accept-Encoding in the cache key and ending with many duplicates because of
slightly different yet equivalent headers, but your suggestion to normalize
it solves it nicely.

Cheers,
Massimiliano


On Tue, Feb 14, 2012 at 2:49 PM, rmalayter <nginx-forum at nginx.us> wrote:

> Just make sure the "Accept-Encoding: gzip" is being passed to your
> back-end, and let the back end do the compression. We actually normalize
> the Accept-Encoding header as well with an if statement. Also use the
> value of the Accept-Encoding header in your proxy_cache_key. This allows
> non-cached responses for those clients that don't support gzip (usually
> coming through an old, weird proxy). So you will get both compressed and
> uncompressed versions in your cache, but with our clients it's like 99%
> compressed versions at any one time.
>
> Example:
>
> server {
>
>  #your server stuff here
>
>   #normalize all accept-encoding headers to just gzip
>   set $myae "";
>   if ($http_accept_encoding ~* gzip) {
>      set $myae "gzip";
>   }
>
>   location / {
>   proxy_pass http://backend;
>   #the following allows comressed responses from backend
>   proxy_set_header Accept-Encoding $myae;
>
>   proxy_cache zone1;
>   proxy_cache_key "$request_uri $myae";
>   proxy_cache_valid 5m;
>   proxy_cache_use_stale error updating;
>
>   }
>
>
>
> }
>
> Posted at Nginx Forum:
> http://forum.nginx.org/read.php?2,222382,222391#msg-222391
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20120214/128b6d50/attachment.html>


More information about the nginx mailing list