Home  >  Article  >  Backend Development  >  Nginx series (seventeen) nginx compression output configuration

Nginx series (seventeen) nginx compression output configuration

WBOY
WBOYOriginal
2016-08-08 09:23:451036browse

1. Configuration file

<code>gzip <span><span>on</span></span>;
gzip_min_length <span>1</span>k;
gzip_buffers <span>16</span><span>64</span>k;
gzip_http_version <span>1.1</span>;
gzip_comp_level <span>6</span>;
gzip_types <span>text</span>/plain <span>application</span>/x-javascript <span>text</span>/css <span>application</span>/xml;
gzip_vary <span><span>on</span></span>;</code>

2. Related parameters

gzip on;
//This command is used to turn on or off the gzip module (on/off)

gzip_min_length 1k;
//Set the minimum number of bytes of the page that is allowed to be compressed. The number of bytes of the page is obtained from the content-length of the header. The default value is 0, which compresses the page regardless of its size. It is recommended to set the number of bytes to be greater than 1k. If it is less than 1k, it may become more and more compressed.

gzip_buffers 4 16k;
//Set the system to obtain several units of cache for storing the gzip compression result data stream. 4 16k means to apply for memory in units of 16k, which is 4 times the original data size of the installation in units of 16k.

gzip_http_version 1.1;
//Identify the http protocol version (1.0/1.1)

gzip_comp_level 2;
//gzip compression ratio, 1 has the smallest compression ratio and the fastest processing speed, 9 has the highest compression ratio but the slowest processing speed (fast transmission but consumes more CPU)

gzip_types text/plain application/x-javascript text/css application/xml
//Match the mime type for compression. Regardless of whether it is specified or not, the "text/html" type will always be compressed.

gzip_vary on;
//It is related to the http header. Add a vary header for the proxy server. Some browsers support compression and some do not, so to avoid waste, the unsupported ones are also compressed. Therefore, it is judged based on the client's HTTP header. Need to compress

The above introduces the nginx compression output configuration of Nginx series (seventeen), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn