The method of Nginx server to realize data static compression _nginx

Source: Internet
Author: User
Tags auth gz file nginx server

Nginx implementation of static compression is actually like the Apache gzip compression, this compression is common to some of the things we have, the following I introduce some practices.

In the construction of Squid Web page acceleration, for large CSS or JS to be compressed, and then cache, this can improve the reduction of download volume to improve the speed of the page response. If you use the previous version of Squid 3.0 and use the Ngnix server, you may encounter the following problems: Do not use squid directly open the page, the client returned is the state of compression, if enabled squid acceleration will find that the downloaded page is not compressed state. This is mainly caused by a static cache module (Ngx_http_gzip_static_module) that does not start Ngnix.

Open the static cache problem to solve

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;

#找不到预压缩文件, 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公共配置 

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


For requests that support gzip, the reverse proxy cache server will return the gzip content, and the client that does not support gzip returns the original content.

Copy Code code as follows:
Gzip_vary on;

1.gzip_static configuration priority is higher than gzip
2. After opening the nginx_static, for any file will first find whether there is a corresponding GZ file
3.gzip_types setting is not valid for gzip_static

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.