Gziping static files

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.

Is there any way around ?

Posted at Nginx Forum:

On Fri, Jul 15, 2011 at 3:29 AM, sarim [email protected] wrote:

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


RPM

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.


Brian A.

sarim Wrote:

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 :frowning:

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
}

Posted at Nginx Forum:

Ryan M. Wrote:

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 :frowning:

Posted at Nginx Forum:

gzip_http_version 1.0;
Does the trick :smiley: :smiley: :smiley:
Thank you very much rmalayter. :slight_smile:

Posted at Nginx Forum: