Welcome! Log In Create A New Profile

Advanced

Re: Can proxy_cache gzip cached content?

February 17, 2012 08:04AM
On Wed, Feb 15, 2012 at 3:55 PM, rmalayter <nginx-forum@nginx.us> wrote:

>
> There's no reason the "backend" for your caching layer cannot be another
> nginx server block running on a high port bound to localhost. This
> high-port server block could do gzip compression, and proxy-pass to the
> back end with "Accept-Encoding: identity", so the back-end never has to
> do compression. The backend server will have to use "gzip_http_version
> 1.0" and "gzip_proxied any" to do compression because it is being
> proxied from the front-end.
>

Ah, good point. I tried to take this an extra step further by using a
virtual host of the same server as "compression backend" and it appears to
work nicely. Below is what I did so far, in case anyone is looking for the
same and Google leads them here.

(Feels a bit like getting out of the door and back in through the window :)
but perhaps just like we have internal redirects it would be possible to
use ngx_lua to simulate an internal proxy and avoid the extra HTTP request.)

proxy_cache_path /var/lib/nginx/cache/myapp
levels=1:2
keys_zone=myapp_cache:10m
max_size=1g
inactive=2d;

log_format cache '***$time_local '
'$upstream_cache_status '
'Cache-Control: $upstream_http_cache_control '
'Expires: $upstream_http_expires '
'$host '
'"$request" ($status) '
'"$http_user_agent" '
'Args: $args ';

access_log /var/log/nginx/cache.log cache;

upstream backend {
server localhost:8002;
}

server { # this step only does compression
listen 85;

server_name myapp.local;
include proxy_params;

location / {
gzip_http_version 1.0;
proxy_set_header Accept-Encoding identity;
proxy_pass http://backend;
}
}

server {
listen 80;

server_name myapp.local;
include proxy_params;

location / {
proxy_pass http://127.0.0.1:85;
}

location /similar-to {
proxy_set_header Accept-Encoding gzip;
proxy_cache_key "$scheme$host$request_uri";
proxy_cache_valid 2d;
proxy_cache myapp_cache;
proxy_pass http://127.0.0.1:85;
}
}


> Also note there may be better options in the latest nginx versions, or
> by using the gunzip 3rd-party module:
> http://mdounin.ru/hg/ngx_http_gunzip_filter_module/file/27f057249155/README
>
> With the gunzip module, you can configure things so that you always
> cache compressed data, then only decompress it for the small number of
> clients that don't support gzip compression.
>

This looks perfect for having a gzip-only cache, which may not lead to save
that much disk space but it certainly helps with mind space.

Cheers,
Massimiliano
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Can proxy_cache gzip cached content?

bard February 14, 2012 07:08AM

Re: Can proxy_cache gzip cached content?

rmalayter February 14, 2012 08:49AM

Re: Can proxy_cache gzip cached content?

bard February 14, 2012 07:42PM

Re: Can proxy_cache gzip cached content?

rmalayter February 15, 2012 09:55AM

Re: Can proxy_cache gzip cached content?

bard February 17, 2012 08:04AM

Re: Can proxy_cache gzip cached content?

bard February 18, 2012 03:44PM

Re: Can proxy_cache gzip cached content?

Maxim Dounin February 18, 2012 06:32PM

Re: Can proxy_cache gzip cached content?

bard February 19, 2012 05:04AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 285
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready