Can proxy_cache gzip cached content?

rmalayter nginx-forum at nginx.us
Tue Feb 14 13:49:47 UTC 2012


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



More information about the nginx mailing list