Enable gzip on Nginx

Posted by Rob Wilkerson on Server Fault See other posts from Server Fault or by Rob Wilkerson
Published on 2012-08-30T15:33:10Z Indexed on 2012/08/30 15:39 UTC
Read the original article Hit count: 277

Filed under:
|
|
|
|

Yes, I know that there are a lot of other questions that seem exactly like this out there. I think I must've looked all of them. Twice. In desparation, I'm adding another in case my specific configuration is the issue. Bear with me.

First, the question: What do I need to do to get gzip compression to work?

I have an Ubuntu 12.04 server installed running nginx 1.1.19. Nginx was installed with the following packages:

nginx
nginx-common
nginx-full

The http block of my nginx.conf looks like this:

http {
  include /etc/nginx/mime.types;

  access_log /var/log/nginx/access.log;

  sendfile on;

  keepalive_timeout  65;
  tcp_nodelay        on;

  gzip  on;
  gzip_disable "msie6";

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

Both PageSpeed and YSlow are reporting that I need to enable compression. I can see that the request headers indicate Accept-Encoding:gzip,deflate,sdch, but the response headers do not have the corollary Content-Encoding header.

I've tried various other config values (gzip_vary on, gzip_http_version 1.0, etc.), but no joy.

As far as I know, I can only assume that nginx was compiled with compression support, but if there's any way to verify that, I'd love to know.

If anyone sees anything I'm missing or can suggest further debugging, please let me know. I'm no sysadmin and I'm new to Nginx so I've exhausted everything I can think of or have read.

Thanks.

© Server Fault or respective owner

Related posts about linux

Related posts about ubuntu