atom feed6 messages in ru.sysoev.nginxRe: Gziping static files
FromSent OnAttachments
sarimJul 15, 2011 1:28 am 
Ryan MalayterJul 26, 2011 7:39 am 
Akins, BrianJul 26, 2011 8:57 am 
sarimAug 11, 2011 2:43 am 
rmalayterAug 11, 2011 6:49 am 
sarimAug 11, 2011 7:02 am 
Subject:Re: Gziping static files
From:rmalayter (ngin@nginx.us)
Date:Aug 11, 2011 6:49:42 am
List:ru.sysoev.nginx

sarim Wrote:

-------------------------------------------------------

Ryan Malayter Wrote:

nginx server on port 80/443 listening on public-facing IP proxy_cache enabled gzip enabled | V nginx server on localhost port 20080 gzip enabled | V your back-end server

Just tried to do that, but nginx is not caching gziped files. It caches in un-gziped state, so nginx gziping on every hit :(

The middle tier needs to have gzip enabled, as well as the front-end tier. You will also need to enable gzip for HTTP 1.0 on the middle tier using "gzip_http_version 1.0;" This is because nginx uses HTTP 1.0 to talk with back-end servers (which in this case is nginx itself). Finally, consider normalizing the gzip headers and adding it to your proxy_cache_key at the frontmost layer, like so:

#normalize all incoming accept-encoding headers to just gzip or empty string #prevents caching of multiple versions of files based on differing browser accept-encoding headers set $myae ""; #use empty string if accept-encoding does not contain gzip if ($http_accept_encoding ~* gzip) { set $myae "gzip"; } location <whatever> { proxy_pass http://localhost:20080; #middle tier doing compression proxy_set_header Host $host; proxy_set_header Accept-Encoding $myae; proxy_cache zone1; proxy_cache_key "$request_uri $myae"; #use normalized accept encoding as part of cache key }

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,212423,213699#msg-213699