5

Our web servers are running IIS 7 and are configured to compress dynamic and static content. When I hit these servers directly, gzip compression works.

I recently placed nginx in front of them, and gzip compression has stopped. I was able to work around this by explicitly enabling gzip compression on nginx itself, but that seems a little inefficient considering I have half a dozen backends and only one active nginx box.

It appears that nginx is stripping out the Accept-Encoding header. Does anyone have any advice for how to 'correct' this behavior?

A sample configuration:

upstream backend {
  server 127.0.0.1:8080;
}

server {
  listen   80;
  proxy_set_header        Host            $host;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

  location / {
    proxy_pass http://backend;
  }
}
Michael Gorsuch
  • 2,378
  • 1
  • 21
  • 24

3 Answers3

4

I'm not sure since how long, but NGINX now DOES support HTTP/1.1 for it's backends, it's just not a standard feature. You can enable it by setting proxy_http_version. Very useful for when your backend servers are on vhosts. For example:

location / {
  proxy_set_header X-Real-IP $remote_addr;
  proxy_pass http://my-backend-vhost.example.com/;
  proxy_http_version 1.1;
}

Ref: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version

MichielB
  • 591
  • 2
  • 6
3

Nginx is a HTTP/1.0 reverse proxy, gzip compression was not in the HTTP specification until HTTP/1.1.

Thus nginx will not send gzip accept-encoding header because it simply doesn't accept it. The proper way to implement gzip handling in nginx is to either talk fastcgi to the backend or to gzip using nginx.

Martin Fjordvald
  • 7,749
  • 1
  • 30
  • 35
3

Apparently it is possible to do this! Via email:

[nginx does do HTTP/1.0], but you can totally do gzip over HTTP 1.0 and we do. The gzip'd content is passed through untouched by nginx, we pre gzip level 9 all our static content, so this is optimal.

nginx can be configured to identify browsers that can do gzip and either foward all the correct headers to the backend and/or do the gzip itself

I think the primary reason nginx doesn't support 1.1 to the backends to because of chunked encoding. (which it does support on the front end) It adds to the complexity of dealing with connections that die mid-stream.

Jeff Atwood
  • 13,104
  • 20
  • 75
  • 92
  • Welll, that is very nice news, but how the heck do we actually implement that? Using latest nginx 1.7.9, and it is stripping the accept-encoding in request going to back end servers.... – Jonesome Reinstate Monica Oct 23 '15 at 16:54