Hi,
I know nginx’s gzip module can compress files onthefly, and gzip_static
module can serve manually gziped file.
Now is there any module/way available to cache the onthefly compression
? I dont want to compress all static files manually, i want nginx to
compress a file first, then save it to cache, then serve the cached
gziped version as long as the main file is not changed.
There are rumors of a gzip cache feature coming that I have seen here.
For now, you can have nginx proxy to itself, with the intermediate
doing the compression. So it would be something like this:
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
Now is there any module/way available to cache the onthefly compression
? I dont want to compress all static files manually, i want nginx to
There are rumors of a gzip cache feature coming that I have seen here.
I’m working on getting some code we wrote to be released as open source
that
does just that.
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 {
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
}