Nginx开启Gzip压缩大幅提高页面加载速度
Nginx 页面 开启 加载 压缩 速度 gzip
2023-09-14 08:59:34 时间
Nginx开启Gzip压缩大幅提高页面加载速度 http://www.veryhuo.com/a/view/51706.html 刚刚给博客加了一个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,所以没压缩
相关文章
- 前后端项目部署-4, flask+Gunicorn+gevent+supervisor+nginx+redis,docker-compose部署
- Nginx配置文件(nginx.conf)配置详解
- nginx优化:配置gzip压缩页面提高访问速度(nginx1.18.0)
- 运维基础之Nginx(1)简介、安装、使用
- 解决Nginx的connect() to 127.0.0.1:8080 failed (13: Permission denied) while connect
- Nginx upstream_keepalive_module 优化后端连接
- nginx指令(alias、set、proxy_pass、rewrite、upstream)、跨域问题、防盗链、缓存、gzip压缩
- 【nginx配置】 proxy_pass反向代理配置中url后面加不加/的说明
- openresty获取Nginx uri中的单一变量
- nginx lua示例
- 解决nginx下vue单页面刷新问题
- 【异常】Nginx报错[emerg]: unknown directive “user“ in /usr/local/nginx/conf/nginx.conf:xx报错处理
- 【异常】Nginx报错: [emerg] unknown directive ““ in /usr/local/nginx/nginx.conf:xx
- nginx 设置错误的自己定义404页面跳转到500
- Nginx 配置Websocket
- centos 源码编译安装nginx 1.18.0 教程 nginx安装脚本
- django+uwsgi+nginx数据表过大引起"out of memory for query result"
- 【Nginx】入门看这一篇就够啦,nginx 简介、安装、工作原理、工作方式、详解配置文件
- Docker安装PHP5及Nginx环境
- Nginx(5):进程绑定CPU:从nginx源码里给你刨功能出来
- Nginx(4):守护进程,一份nginx实现,一份我的实现,看着拿呗
- CentOS 6.8 编译安装 Nginx 和 echo-nginx-module 模块