Adding gzip compression to a Rancher HAProxy Load Balancer

Adding gzip compression to a Rancher HAProxy Load Balancer

Say you want to gzip application/json coming from your application you can put a Rancher Load Balancer (HAProxy) in front and add the following config to the defaults section:

compression algo gzip
compression type application/json

This will then gzip all responses with Content-Type: application/json if the client supports compression.

A simple benchmark suggests that doing it at the LB instead of within the application is more performant than, say, using the compression middleware in a node.js express application

For a more complete set of MIME types which can be compressed, use this:

compression type text/html "text/html; charset=utf-8" text/html;charset=utf-8 text/plain text/css text/javascript application/x-javascript application/javascript application/ecmascript application/rss+xml application/atomsvc+xml application/atom+xml application/atom+xml;type=entry application/atom+xml;type=feed application/cmisquery+xml application/cmisallowableactions+xml application/cmisatom+xml application/cmistree+xml application/cmisacl+xml application/msword application/vnd.ms-excel application/vnd.ms-powerpoint image/svg+xml