Method Description of CLB Enabling Gzip Configuration and Detection
Last Updated At: 2025-10-21 09:10:00
In Public Network CLB instance, HTTP/HTTPS protocol supports users to enable the gzip compression feature by default. Enabling the gzip feature to compress web pages can effectively reduce the amount of data transmitted over the network and increase the access speed of client browsers. During use, pay attention to the following matters:
Notes
Backend CVM needs to enable GZIP support synchronously
For the common Nginx service container, you must enable GZIP in its configuration file (nginx.conf by default) and restart the service.gzip on;The file types currently supported by the CLB are as follows. You can specify the file type for compression in the gzip_types configuration item
application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component;
Description:
The GZIP support for the above file types must be enabled in the CLB backend CVM business software.
The client request must contain a compressed request marker.
Compression needs to be enabled, and the client request must carry the following markers:Accept-Encoding: gzip,deflate,sdch
Sample of Backend CVM Enabling GZIP Process Support
Sample of CVM Running Environment: Debian 6
Use vim to open the Nginx configuration file according to the user path:
vim /etc/nginx/nginx.confFind the following code:
gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/html application/json;
The syntax details of the above code is as follows:
- gzip: Enable or disable the gzip module.
Syntax:gzip on/off.
Scope: http, server, location. - gzip_min_length: Sets the minimum number of bytes allowed for compressed pages. The number of bytes in a page is obtained from the Content-Length in the header. The default value is 1 k.
Syntax:gzip_min_length length
Scope: http, server, location - gzip_buffers: Set the system to obtain several units of buffer for storing gzip compression result data stream. 16 k means that the memory is requested in units of 16 k, which is 4 times the original data size in units of 16 k.
Syntax:gzip_buffers number size
Scope: http, server, location - gzip_http_version: represents the minimum HTTP version that can use the gzip feature. Setting HTTP/1.0 represents the minimum HTTP version that needs to use the gzip feature, so it can be upward compatible with HTTP/1.1. Since Converge Cloud now supports HTTP/1.1 across the entire internet, no changes are required.
Syntax:gzip_http_version 1.0 | 1.1;
Scope: http, server, location - gzip_comp_level: gzip compression ratio, ranging from 1 to 9. 1 has the lowest compression ratio and the fastest processing speed, and 9 has the highest compression ratio but the slowest processing speed (fast transmission but more CPU consumption).
Syntax:gzip_comp_level 1..9
Scope: http, server, location - gzip_types: Match the MIME type for compression. By default, the text/html type is compressed. In addition, gzip under Nginx does not compress static resource files such as javascript and images by default. You can specify the MIME type that needs to be compressed through gzip_types. If it is not a set value, no compression is performed. For example, if you need to compress json format data, you need to add application/json type data in this statement.
The supported types are as follows:
text/html text/plain text/css application/x-javascript text/javascript application/xml
Syntax: gzip_types mime-type [mime-type ...]
Scope: http, server, location.
If you have modified the configuration, save the file and exit, then go to the Nginx bin file directory and execute the following command to reload Nginx:
./nginx -s reload
Use the curl command to test whether gzip is successfully enabled:
curl -I -H "Accept-Encoding: gzip, deflate" "http://convergecloud.com/example/"