4

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.

Rob Wilkerson
  • 1,465
  • 4
  • 17
  • 25

1 Answers1

5

If nginx doesn't complaing about gzip on; being in your configuration file, then it's been compiled with the gzip module. By default, it only compresses text/html responses. You need to configure gzip_types if you want to compress anything else (css, js, etc).

kolbyjack
  • 8,039
  • 2
  • 36
  • 29
  • It looks like this was the key. I can't believe that I didn't bump into a single resource that indicated that `gzip_type` values were required for anything other than html, but I sure don't remember seeing that. Thanks for your help. – Rob Wilkerson Aug 30 '12 at 16:06
  • 1
    @Rob Wilkerson I'd suggest in future to look at documentation first and SF second. http://wiki.nginx.org/HttpGzipModule is not that large and checking gzip_types would show you the default is text/html. – Martin Fjordvald Aug 30 '12 at 17:24
  • I have `gzip_types text/css text/plain text/xml application/xml application/javascript application/x-javascript text/javascript application/json text/x-json image/gif image/jpeg image/png;` and NGINX doesn't set `Content-Encoding` header. When I check `nginx -V`, it only has `--with-http_gzip_static_module` and no `ngx_http_gzip_module`. And no any complaints about `gzip on;` – Green Dec 09 '15 at 12:42