多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 服務器 > Nginx開啟Gzip壓縮大幅提高頁面加載速度

Nginx開啟Gzip壓縮大幅提高頁面加載速度

來源:程序員人生   發布時間:2013-12-12 04:55:42 閱讀次數:3150次

剛剛給博客加了一個500px相冊插件,lightbox引入了很多js文件和css文件,頁面一下子看起來非常臃腫,所以還是把Gzip打開了。

環境:Debian 6

1、Vim打開Nginx配置文件

vim /usr/local/nginx/conf/nginx.conf

2、找到如下一段,進行修改

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 application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary off;
gzip_disable "MSIE [1-6].";

3、解釋一下

第1行:開啟Gzip

第2行:不壓縮臨界值,大于1K的才壓縮,一般不用改

第3行:buffer,就是,嗯,算了不解釋了,不用改

第4行:用了反向代理的話,末端通信是HTTP/1.0,有需求的應該也不用看我這科普文了;有這句的話注釋了就行了,默認是HTTP/1.1

第5行:壓縮級別,1-10,數字越大壓縮的越好,時間也越長,看心情隨便改吧

第6行:進行壓縮的文件類型,缺啥補啥就行了,JavaScript有兩種寫法,最好都寫上吧,總有人抱怨js文件沒有壓縮,其實多寫一種格式就行了

第7行:跟Squid等緩存服務有關,on的話會在Header里增加"Vary: Accept-Encoding",我不需要這玩意,自己對照情況看著辦吧

第8行:IE6對Gzip不怎么友好,不給它Gzip了

4、:wq保存退出,重新加載Nginx

/usr/local/nginx/sbin/nginx -s reload

5、用curl測試Gzip是否成功開啟

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

頁面成功壓縮

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

css文件成功壓縮

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

js文件成功壓縮

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

圖片成功壓縮

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

最后來個不到1K的文件,由于我的閾值是1K,所以沒壓縮

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲α片| 男人午夜天堂 | 久久中文字幕亚洲精品最新 | 亚洲精品欧美日韩 | 亚洲一区二区精品推荐 | 最近中文字幕3 | 欧美69xxxx | xxxxxx日本处大片免费看 | 毛片毛| 国产福利不卡视频在免费播放 | jiuse在线| 亚洲三级a | porn在线视频一区二区 | 一级毛片区 | 精品一区二区三区自拍图片区 | 国产在线乱子伦一区二区 | 拍拍拍免费高清在线观看视频 | 亚洲精品www久久久久久 | 第一页欧美| 一级片久久 | 日本欧美在线 | 亚洲欧洲日产国码二区在线 | 中文字幕在线精品视频入口一区 | 欧美精品日韩 | 日韩一级欧美一级在线观看 | 久久精品国产一区二区三区 | 国产精品久久毛片蜜月 | 午夜黄视频 | 成人娱乐网 | 亚洲国产精品第一区二区三区 | 毛片在线不卡 | 国产在线永久视频 | 日韩欧美精品在线观看 | 中文国产成人精品久久一区 | 国语精品91自产拍在线观看二区 | 亚洲国产一区二区三区最新 | 亚洲在线偷拍自拍 | 在线观看麻豆精品国产不卡 | 欧美日韩欧美 | 最近最新的免费中文字幕 | 成人免费视频在 |