Compression
HTTP compression allows you to shrink the body of a response before it's relayed to a client, which results in using less network bandwidth per request. From a client's perspective, this reduces latency.
Enable compression
-
In a
frontend
,backend
,listen
ordefaults
section, add acompression
directive. Set itsalgo
parameter to any combination of deflate, gzip, identity or raw-deflate. Responses will be compressed only if they are not already compressed:backend web_servers filter compression compression algo gzip
-
Add a
compression type
directive, which specifies the MIME types to compress:backend web_servers filter compression compression algo gzip compression type text/css text/html text/javascript application/javascript text/plain text/xml application/json
-
Optionally, add a
compression offload
directive, which states that HAProxy Enterprise will remove the Accept-Encoding header before forwarding a request to backend servers, which prevents the servers from performing compression, offloading that work to HAProxy Enterprise:backend web_servers filter compression compression algo gzip compression type text/css text/html text/javascript application/javascript text/plain text/xml application/json compression offload
Proxy-level settings
The following directives in a frontend
, backend
, listen
or defaults
section apply to compression:
| Sets the list of supported compression algorithms. Valid values include:
| ||||||||
| MIME types to apply compression to, read from the Content-Type response header field. If not set, HAProxy Enterprise tries to compress all responses that are not compressed by the server. | ||||||||
| Instructs HAProxy Enterprise to remove the Accept-Encoding header from the request before forwarding it to the server. Thus, HAProxy Enterprise compresses the response, not the server. |
Process-level settings
Add any of the following directives to the global
section to affect compression:
| Sets the maximum per-process input compression rate to <number> kilobytes per second. For each session, if the maximum is reached, the compression level will be decreased during the session. If the maximum is reached at the beginning of a session, the session will not compress at all. If the maximum is not reached, the compression level will be increased up to |
| Sets the maximum CPU usage HAProxy Enterprise can reach before stopping the compression for new requests or decreasing the compression level of current requests. It works like |
| Sets the maximum compression level. The compression level affects CPU usage during compression. Each session using compression initializes the compression algorithm with this value. The default is 1. |
Compression restrictions
HAProxy Enterprise disables HTTP compression when:
The request does not advertise a supported compression algorithm in the Accept-Encoding header
The response message is HTTP/1.0
The HTTP status code is not 200, 201, 202 or 203
The response contains neither a Content-Length header nor a Transfer-Encoding header whose last value is chunked
The response contains a Content-Type header whose first value starts with multipart
The response contains a Cache-Control header with a value of no-transform
The response contains a Content-Encoding header, indicating that the response is already compressed (see
compression offload
)The response contains an invalid ETag header or multiple Etag headers
Next up
Circuit Breaking