0

I have a Django app with Gunicorn, going throught Varnish and served with Nginx.

MyDjangoApp --> Gunicorn --> Varnish --> Nginx --> Client

Which one of the gzip params I have to keep ?

In Django ?

MIDDLEWARE_CLASSES = (
    # Remove Django Gzip middleware as we already have it in nginx ?
    'django.middleware.gzip.GZipMiddleware',
    ....

In Nginx ?

http {
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    ....

In Varnish ?

sub vcl_backend_response {
    if (bereq.url ~ "html$") {
            set beresp.do_gzip = true;
    }
....

Do I have to activate on all confs or Just Nginx ? If I activate the GZipMiddleware in Django for ex, I should not need to activate it on Varnish & Nginx or I'm missing something ?

kollo
  • 1,285
  • 3
  • 20
  • 33

1 Answers1

1

My approach to where gzip compression should be done is this:

Enable gzip on a web server that is behind Varnish.

In your case, you can keep it in Django.

Do not alter default Varnish gzip parameters. (let it handle gzip using default behaviour)

Why?

  • Varnish can store gzipped object in its cache (good, saves storage).
  • No CPU time will be spent for compression while serving a cached object (most of the clients will ask for compressed object and Varnish can just serve it directly)

So you would save both CPU and RAM by doing compression on appropriate level.

Danila Vershinin
  • 8,725
  • 2
  • 29
  • 35