I just added a 500px album plug-in to my blog. lightbox introduced a lot of js files and css files, and the page suddenly looked very bloated, so I opened Gzip. Environment: Debian61 and Vim open the Nginx configuration file vim/usr/local/nginx/conf/nginx. conf2. find the following section and modify gzipon;
I just added a 500px album plug-in to my blog. lightbox introduced a lot of js files and css files, and the page suddenly looked very bloated, so I opened Gzip.
Environment: Debian 6
1. run Vim to open the Nginx configuration file.
Vim/usr/local/nginx/conf/nginx. conf
2. find the following section and modify it.
Gzip on;
Gzip_min_length 1 k;
Gzip_buffers 4 16 k;
# Gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
Gzip_vary off;
Gzip_disable "MSIE [1-6] \.";
3. explain
Row 3: enable Gzip
Row 3: no compression critical value. compression is required if the compression value is greater than 1 kB.
Row 3: buffer, that is, well, you don't have to explain it. you don't have to change it.
Row 3: if a reverse proxy is used, the end communication is HTTP/4th. if you want to use reverse proxy, you don't need to read this popular article. if you have this sentence, just comment it out, the default value is HTTP/1.1.
Row 5th: compression level, 1-10. the larger the number, the better the compression time. the longer the time is, let's change your mood.
Row 3: the type of the file to be compressed. you just need to fill in what you need. JavaScript can be written in either of the following ways. some people complain that the js file is not compressed, in fact, just write one more format.
Row 7th: it is related to cache services such as Squid. if on is used, "Vary: Accept-Encoding" will be added to the Header. I don't need this stuff. let's take a look at it.
Row 8th: IE6 is not very friendly to Gzip and does not provide it with Gzip.
4.: wq is saved and exited, and Nginx is reloaded.
/Usr/local/nginx/sbin/nginx-s reload
5. use curl to test whether Gzip is enabled successfully
Curl-I-H "Accept-Encoding: gzip, deflate" http://www.slyar.com/blog"
HTTP/1.1 200 OK
Server: nginx/1.0.15
Date: Sun, 26 Aug 2012 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 compressed
Curl-I-H "Accept-Encoding: gzip, deflate" http://www.slyar.com/blog/wp-content/plugins/photonic/include/css/photonic.css"
HTTP/1.1 200 OK
Server: nginx/1.0.15
Date: Sun, 26 Aug 2012 18:21:25 GMT
Content-Type: text/css
Last-Modified: Sun, 26 Aug 2012 15:17:07 GMT
Connection: keep-alive
Expires: Mon, 27 Aug 2012 06:21:25 GMT
Cache-Control: max-age = 43200
Content-Encoding: gzip
The css file is compressed successfully.
Curl-I-H "Accept-Encoding: gzip, deflate" http://www.slyar.com/blog/wp-includes/js/jquery/jquery.js"
HTTP/1.1 200 OK
Server: nginx/1.0.15
Date: Sun, 26 Aug 2012 18:21:38 GMT
Content-Type: application/x-javascript
Last-Modified: Thu, 12 Jul 2012 17:42:45 GMT
Connection: keep-alive
Expires: Mon, 27 Aug 2012 06:21:38 GMT
Cache-Control: max-age = 43200
Content-Encoding: gzip
The js file is compressed successfully.
Curl-I-H "Accept-Encoding: gzip, deflate" http://www.slyar.com/blog/wp-content/uploads/2012/08/2012-08-23_203542.png"
HTTP/1.1 200 OK
Server: nginx/1.0.15
Date: Sun, 26 Aug 2012 18:22:45 GMT
Content-Type: image/png
Last-Modified: Thu, 23 Aug 2012 13:50:53 GMT
Connection: keep-alive
Expires: Tue, 25 Sep 2012 18:22:45 GMT
Cache-Control: max-age = 2592000
Content-Encoding: gzip
Image compressed
Curl-I-H "Accept-Encoding: gzip, deflate" http://www.slyar.com/blog/wp-content/plugins/wp-multicollinks/wp-multicollinks.css"
HTTP/1.1 200 OK
Server: nginx/1.0.15
Date: Sun, 26 Aug 2012 18:23:27 GMT
Content-Type: text/css
Content-Length: 180
Last-Modified: Sat, 02 May 2009 08:46:15 GMT
Connection: keep-alive
Expires: Mon, 27 Aug 2012 06:23:27 GMT
Cache-Control: max-age = 43200
Accept-Ranges: bytes
The last file is less than 1 K. since my threshold is 1 K, it is not compressed.