2

I have a nginx server acting as load balancer, which delegates requests to other application servers.

When I try to request a asset directly to the application server, the asset is served in it's gzipped version, sample:

➜ ~ curl -IH 'Accept-Encoding: gzip, deflate' http://application/asset.css HTTP/1.1 200 OK Server: nginx/1.6.2 Date: Thu, 15 Sep 2016 14:13:03 GMT Content-Type: text/css Content-Length: 35038 Connection: keep-alive Content-Encoding: gzip Expires: Thu, 31 Dec 2037 23:55:55 GMT Cache-Control: max-age=315360000 Cache-Control: public

While the same request to the load balancer, returns the non-compressed version of the asset. ➜ ~ curl -IH 'Accept-Encoding: gzip, deflate' https://load-balancer/asset.css HTTP/1.1 200 OK Server: nginx/1.6.2 Date: Thu, 15 Sep 2016 14:16:15 GMT Content-Type: text/css Content-Length: 240442 Connection: keep-alive Expires: Thu, 31 Dec 2037 23:55:55 GMT Cache-Control: max-age=315360000 Cache-Control: public Accept-Ranges: bytes

Here my configuration for the LB: location / { client_max_body_size 10M; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto https; # if use ssl proxy_redirect off; proxy_pass http://application; }

thanks in advance

3

Solved!

I figured out myself that the request sent from the load balancer to the upstream (application server), is done in HTTP/1.0, while the nginx server in the application side, only compressed the files when the request was in HTTP >= 1.1, due to default params.

http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_http_version

| improve this answer | |
  • Perhaps you could share how you solved this issue, rather than just what it is, and accept your own answer. – Tim Sep 15 '16 at 19:35
  • I think the answer, with the link above self explains how to solve the problem :) Solution for lazy minds: just configure the parameter gzip_http_version, which defines the minimum HTTP version to compress assets with. – Iván Guillén Sep 16 '16 at 11:29
  • Great :) Once you can, please mark your answer as accepted, though I think new users have to wait a bit before they can do that. – Tim Sep 16 '16 at 19:18
3

There is another way to solve this. You can set a higher HTTP protocol version for proxying connections to upstream. It can be done by this parameter: proxy_http_version 1.1;

It would be a better choice because this way you can benefit from lots of HTTP/1.1 advantages like persistent connections and Extra new status codes.

For example this is my own settings block:

server {
    listen       80;
    server_name  domain.tld;
    location / {
         include proxy_params;
         proxy_http_version 1.1;
         proxy_pass http://my-up-stream;
    }
}

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.