標籤:power tom xxx csdn buffer min 啟用 rpc script
為了降低tomcat服務的壓力,把頁面上的圖片採用windows版的nginx進行載入,由於有些圖片比較大,載入特別的慢,所以在nginx中開啟了gzip的壓縮功能。載入圖片的速度快了很多。
通過站長工具中的"網頁GZIP壓縮檢測"工具檢測圖片的壓縮率達到了69.53%,如:
下面介紹nginx.conf檔案是怎麼配置的:
1、開啟nginx.conf設定檔;
2、找到#gzip on這句,如:
3.在把#gzip on 改成下面代碼:
#開啟Gzip gzip on; #不壓縮臨界值,大於10K的才壓縮,一般不用改 gzip_min_length 10k; #設定gzip申請記憶體的大小,其作用是按塊大小的倍數申請記憶體空間 gzip_buffers 4 48k; #用了反向 Proxy的話,末端通訊是HTTP/1.0,有需求的應該也不用看我這科普文了;有這句的話注釋了就行了,預設是HTTP/1.1 gzip_http_version 1.0; #壓縮層級,1-9,數字越大壓縮的越好,時間也越長,看心情隨便改吧 gzip_comp_level 6; #設定需要壓縮的MIME類型,非設定值不進行壓縮 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的話會在Header裡增加"Vary: Accept-Encoding" gzip_vary off; #IE6對Gzip不怎麼友好,不給它Gzip了 gzip_disable "MSIE [1-6]\.";
改成後代碼如:
4.重新載入Nginx;
<span style="white-space:pre"> </span>在linux中重啟:/usr/local/nginx/sbin/nginx -s reload 在windows中重啟:C:\server\nginx-1.0.2>nginx.exe -s reload
5.測試nginx壓縮是否啟用:
(1).頁面成功壓縮
<span style="white-space:pre"> </span>curl -I -H "Accept-Encoding: gzip, deflate" "http://wwww.xxxx.com/mr_smile2014" HTTP/1.1 200 OK Server: nginx/1.9.1 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
(2).css檔案成功壓縮
curl -I -H "Accept-Encoding: gzip, deflate" "http://wwww.xxxx.com/mr_smile2014/index.css" HTTP/1.1 200 OKServer: nginx/1.9.1Date: Sun, 26 Aug 2012 18:21:25 GMTContent-Type: text/cssLast-Modified: Sun, 26 Aug 2012 15:17:07 GMTConnection: keep-aliveExpires: Mon, 27 Aug 2012 06:21:25 GMTCache-Control: max-age=43200Content-Encoding: gzip
(3).圖片成功壓縮
curl -I -H "Accept-Encoding: gzip, deflate" "http://wwww.xxxx.com/1_mr_smile2014.jpg" HTTP/1.1 200 OKServer: nginx/1.9.1Date: Sun, 26 Aug 2012 18:22:45 GMTContent-Type: image/pngLast-Modified: Thu, 23 Aug 2012 13:50:53 GMTConnection: keep-aliveExpires: Tue, 25 Sep 2012 18:22:45 GMTCache-Control: max-age=2592000Content-Encoding: gzip
(4)js檔案成功壓縮
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, 26 Aug 2012 18:21:38 GMTContent-Type: application/x-javascriptLast-Modified: Thu, 12 Jul 2012 17:42:45 GMTConnection: keep-aliveExpires: Mon, 27 Aug 2012 06:21:38 GMTCache-Control: max-age=43200Content-Encoding: gzip
原貼地址:51983447
在windows、linux中開啟nginx的Gzip壓縮大大提高頁面、圖片載入速度<轉>