Nginx Turn on gzip compression (pictures, files, CSS)

Source: Internet
Author: User
Tags curl

1, VIM open nginx configuration file

Vim/usr/local/nginx/conf/nginx.conf

2, to find the following paragraph, to modify

gzip on;

Gzip_min_length 1k;

Gzip_buffers 4 16k;

#gzip_http_version 1.0;

Gzip_comp_level 2;

Gzip_types text/plain application/x-javascript text/css application/xml text/javascript image /jpeg image/gif image/png;

Gzip_vary off;

Gzip_disable "MSIE [1-6]\.";

3. Explain

Line 1th: Open gzip

Line 2nd: No compression critical value, greater than 1K compression, generally do not need to change

Line 3rd: Buffer, yes, well, no explanation, no change.

Line 4th: With the reverse agent, the end of the communication is http/1.0, there should be no need to see the needs of the popular science, I have this comment on the line, the default is http/1.1

Line 5th: Compression level, 1-10, the larger the number of compression, the longer the time, look at the mood casually change it

Line 6th: To compress the file type, the lack of what to fill what on the line, JavaScript has two ways to write, the best is written on it, there is always someone complaining JS file is not compressed, in fact, write a format on the line

Line 7th: With squid and other caching services, on the words will be added to the header "Vary:accept-encoding", I do not need this thing, I look at it against the situation to do it

Line 8th: IE6 is not very friendly to gzip, does not give it gzip

4.: Wq save exit, Reload Nginx

/usr/local/nginx/sbin/nginx-s Reload

5, with Curl Test gzip successfully opened

Curl-i-H "accept-encoding:gzip, deflate" "http://www.111cn.net/"
http/1.1 OK
server:nginx/1.0.15
Date:sun, Aug 18:13:09 GMT
content-type:text/html; charset=utf-8
connection:keep-alive
X-POWERED-BY:PHP/5.2.17P1
x-pingback:http://www.slyar.com/blog/xmlrpc.php
content-encoding:gzip

Page successfully compressed

Curl-i-H "accept-encoding:gzip, deflate" "Http://www.ye111cn.nethemes/default/statics/css/lib.css"
http/1.1 
server:nginx/1.0.15
date:sun Aug 18:21:25 GMT content-type:text/css
last-modified: Sun, Aug 15:17:07 GMT
connection:keep-alive
Expires:mon, Aug-06:21:25 GMT Cache-control:max
-age=43200
Content-encoding:gzip

CSS file successfully compressed

Curl-i-H "accept-encoding:gzip, deflate" http://www.111cn.net/Themes/default/statics/js/jquery.min.js "
http/ 1.1 OK
server:nginx/1.0.15
date:sun, Aug 18:21:38 GMT content-type:application/x-javascript<
C4/>last-modified:thu 17:42:45 GMT
connection:keep-alive
Expires:mon, Aug (06:21:38) >cache-control:max-age=43200
Content-encoding:gzip

JS file successfully compressed

Curl-i-H "accept-encoding:gzip, deflate" "Yun_qi_img/2012-08-23_203542.png"
http/1.1 OK
server:nginx/ 1.0.15
date:sun Aug 18:22:45 GMT content-type:image/png
last-modified:thu, Aug 13:50:53 GM T
connection:keep-alive
expires:tue, Sep 18:22:45 GMT
cache-control:max-age=2592000
Content-encoding:gzip

Picture successfully compressed

Curl-i-H "accept-encoding:gzip, deflate" "http://www.slyar.com/blog/wp-content/plugins/wp-multicollinks/ Wp-multicollinks.css "
http/1.1 OK
server:nginx/1.0.15
Date:sun, Aug mb 18:23:27 GMT
Content-type:text/css
content-length:180
Last-modified:sat, May 2009 08:46:15 GMT
Connection: Keep-alive
Expires:mon, Aug 06:23:27 GMT
cache-control:max-age=43200
accept-ranges:bytes

Finally a file of less than 1K, because my threshold is 1K, so no compression

Related Article

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.