In order to reduce the pressure of the Tomcat service, the picture on the page using the Windows version of the Nginx load, because some pictures are larger, loading particularly slow, so in Nginx opened the compression function of gzip. Loading pictures is a lot faster.
The "Web gzip compression detection" tool in Webmaster Tools detects images with a compression rate of 69.53%, such as:
The following describes how the nginx.conf file is configured:
1, open the nginx.conf configuration file ;
2, find #gzip on this sentence, such as:
3. Change the #gzip on to the following code:
#开启Gzip gzip on; #不压缩临界值, more than 1K compression, generally do not have to change gzip_min_length 100k; #设置gzip申请内存的大小, its role is to request memory space in multiples of block size gzip_buffers 4 48k; #用了反向代理的话 , the end of the communication is http/1.0, there should be no need to see me this popular science, there is a comment on the line, the default is http/1.1 gzip_http_version 1.0; #压缩级别, 1-9, the greater the number of compression, the better, the longer the time, Look at the mood to change it gzip_comp_level 6; #设置需要压缩的MIME类型, non-set values are not compressed gzip_types text/plain application/x-javascript text/css Application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; #跟Squid等缓存服务有关, On words will add "vary:accept-encoding" gzip_vary off in the header, #IE6对Gzip不怎么友好, do not give it gzip gzip_disable "MSIE [1-6]\.";
Change to post code such as:
4. Reload Nginx;
<span style= "White-space:pre" ></span> restart in Linux:/usr/local/nginx/sbin/nginx-s reload restart in Windows: \ c \ Server\nginx-1.0.2>nginx.exe-s Reload
5. Test whether Nginx compression is enabled:
(1). Page successfully compressed
<span style= "White-space:pre" ></span>curl-i-H "accept-encoding:gzip, deflate" "HTTP://WWWW.XXXX.COM/MR _smile2014 "http/1.1 Okserver:nginx/1.9.1date:sun, the 18:13:09 gmtcontent-type:text/html; charset=utf-8connection:keep-alivex-powered-by:php/5.2.17p1x-pingback:http://www.slyar.com/blog/ Xmlrpc.phpcontent-encoding:gzip
(2). css file successfully compressed
Curl-i-H "accept-encoding:gzip, deflate" http://wwww.xxxx.com/mr_smile2014/index.css "http/1.1 okserver:nginx/ 1.9.1date:sun, 18:21:25 Gmtcontent-type:text/csslast-modified:sun, 15:17:07 gmtconnection:keep -aliveexpires:mon, 06:21:25 Gmtcache-control:max-age=43200content-encoding:gzip
(3). Picture successfully compressed
Curl-i-H "accept-encoding:gzip, deflate" http://wwww.xxxx.com/1_mr_smile2014.jpg "http/1.1 okserver:nginx/ 1.9.1date:sun, 18:22:45 Gmtcontent-type:image/pnglast-modified:thu, at 13:50:53 Gmtconnection:kee P-aliveexpires:tue, Sep 18:22:45 gmtcache-control:max-age=2592000content-encoding:gzip
(4) JS file successfully compressed
Curl-i-H "accept-encoding:gzip, deflate" "Http://wwww.xxxx.com/mr_smile2014/js/jquery/jquery.js" http/1.1 200 Okserver:nginx/1.9.1date:sun, 18:21:38 Gmtcontent-type:application/x-javascriptlast-modified:thu, 2 Jul 012 17:42:45 Gmtconnection:keep-aliveexpires:mon, 06:21:38 gmtcache-control:max-age=43200content-encoding : gzip
Open Nginx gzip compression in Windows, Linux greatly improve the speed of page and picture loading