The Nginx server implements the method of data static compression

  • 2020-05-09 19:56:42
  • OfStack

The way nginx does static compression is just like apache gzip does static compression, which is something that we do all the time, so let me introduce you to some of them.

When building squid pages to speed up, the large css or js pages are compressed and then cached to increase the speed of page response and reduce the number of downloads. If you are using squid before 3.0 and ngnix server, you may encounter the following problems: if you do not use squid to open the page directly, the client will return a compressed state; if you enable squid acceleration, you will find that the downloaded page is not compressed. This is mainly caused by the failure to start ngnix's static cache module (ngx_http_gzip_static_module).

Turn on the static cache and the problem is solved

1.nginx compilation options


./configure --with-http_gzip_static_module

2. Modify nginx. conf


gzip_static on;

gzip_http_version 1.1;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6] .";
gzip_vary on;

# Unable to find a precompressed file, do dynamic compression  

gzip on;  
gzip_min_length 1000; 
gzip_buffers 4 16k; 
gzip_comp_level 5; 
gzip_types text/plain application/x-javascript text/css application/xml; 
 
#gzip Common configuration  

gzip_http_version 1.1 
gzip_proxied expired no-cache no-store private auth; 


The reverse proxy cache server will return gzip content for requests that support gzip, and the original content for clients that do not support gzip.  

gzip_vary on; 

1.gzip_static configuration priority is higher than gzip
2. After opening nginx_static, the corresponding gz file will be checked for any file
3. The gzip_types setting is not valid for gzip_static


Related articles: