在windows、linux中开启nginx的Gzip压缩大大提高页面、图片加载速度
来源:互联网 发布:免费网页数据抓取工具 编辑:程序博客网 时间:2024/05/22 04:35
为了降低tomcat服务的压力,把页面上的图片采用windows版的nginx进行加载,由于有些图片比较大,加载特别的慢,所以在nginx中打开了gzip的压缩功能。加载图片的速度快了很多。
通过站长工具中的”网页GZIP压缩检测”工具检测图片的压缩率达到了69.53%,如下图:
下面介绍nginx.conf文件是怎么配置的:
1、打开nginx.conf配置文件;
2、找到#gzip on这句,如下图:
3.在把#gzip on 改成下面代码:
- #开启Gzip
- gzip on;
- #不压缩临界值,大于1K的才压缩,一般不用改
- gzip_min_length 100k;
- #设置gzip申请内存的大小,其作用是按块大小的倍数申请内存空间
- gzip_buffers 4 48k;
- #用了反向代理的话,末端通信是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]\.”;
#开启Gzip gzip on; #不压缩临界值,大于1K的才压缩,一般不用改 gzip_min_length 100k; #设置gzip申请内存的大小,其作用是按块大小的倍数申请内存空间 gzip_buffers 4 48k; #用了反向代理的话,末端通信是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
<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
<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 OK
- Server: nginx/1.9.1
- 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
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 OK
- Server: nginx/1.9.1
- 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://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
- curl -I -H “Accept-Encoding: gzip, deflate” “http://wwww.xxxx.com/mr_smile2014/js/jquery/jquery.js”
- HTTP/1.1 200 OK
- Server: nginx/1.9.1
- 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
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
阅读全文
0 0
- 在windows、linux中开启nginx的Gzip压缩大大提高页面、图片加载速度
- 在windows、linux中开启nginx的Gzip压缩大大提高页面、图片加载速度
- 【Gzip】Nginx开启Gzip压缩大幅提高页面加载速度
- Nginx开启Gzip压缩大幅提高页面加载速度
- Nginx开启Gzip压缩大幅提高页面加载速度
- Nginx开启Gzip压缩大幅提高页面加载速度
- Nginx开启Gzip压缩大幅提高页面加载速度
- Nginx开启Gzip压缩大幅提高页面加载速度及相关测试
- Nginx开启Gzip压缩大幅提高页面加载速度及相关测试
- Nginx开启Gzip压缩大幅提高页面加载速度及相关测试
- 在IIS上启用Gzip压缩(HTTP压缩),提高页面加载速度
- phpnow开启gzip压缩提高访问速度
- 实战在 nginx配置中开启gzip压缩
- 使用nginx的gzip大幅度提升页面的加载速度
- 在web项目中使用gzip压缩方式提高速度的东东
- 用mod_deflate来开启Gzip压缩网页提高网站速度
- nginx 开启 gzip 压缩
- Nginx开启Gzip压缩
- 数学之路(1)
- path变量
- 创建、删除、备份数据库
- StopWatch任务执行时间监控
- (转)详解spring 每个jar的作用
- 在windows、linux中开启nginx的Gzip压缩大大提高页面、图片加载速度
- java volatile
- Ubuntu下安装Java,R,R-studio,R-studio Server
- COCO Detection Challenge
- SecureCRT 连接Ubuntu 16.04出现Connection timed out 的问题
- iOS 异常处理机制
- 蚂蚁金服漆远首谈刚完成的AI重大突破及紧缺人才,呼吁国内多点技术性强的大会,少点网红
- Android常用工具之Logutils
- mysql exists和in效率问题