nginx gzip压缩
gzip压缩作用:将响应报⽂发送⾄客户端之前可以启⽤压缩功能,这能够有效地节约带宽,并提⾼响应⾄客户端的速度,压缩会消耗nginx的cpu性能
gzip压缩可以配置http,server和location模块下
0.压缩语法
location ~ .*\.(jpg|gif|png|bmp)$ //~区分大小写, 匹配任意字符开头以.jpg或.bmp结尾,注意这里的jgp等类型需要使用gzip_types调用
gzip on; //开启gzip压缩
gzip_http_version 1.1 //压缩协议版本
gzip_comp_level 3; //压缩比率
gzip_types //压缩类型,根据/usr/local/nginx/conf/mime.types中定义;
1.先不开启压缩
#vim /usr/local/nginx/conf.d/vir.conf
server {
listen 80;
server_name test.com www.test.com;
root /webroot/www;
location ~ .*\.(jpg|gif|png|bmp)$ {
#gzip on;
#gzip_http_version 1.1;
#gzip_comp_level 3;
#gzip_types text/plain application/json application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-ms-bmp;
}
}
#nginx -t
#nginx -s reload
2.文件大小
ll -h /webroot/www/test.bmp
-rw-r--r-- 1 root root 453K 3月 14 18:43 /webroot/www/test.bmp
3.验证:文件没有被压缩,文件传输大小还是400多K

4.开启压缩
#vim /usr/local/nginx/conf.d/vir.conf
server {
listen 80;
server_name test.com www.test.com;
root /webroot/www;
location ~ .*\.(jpg|gif|png|bmp)$ {
gzip on;
gzip_http_version 1.1;
gzip_comp_level 3;
gzip_types text/plain application/json application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-ms-bmp;
}
}
#nginx -t
#nginx -s reload
5.验证:文件传输大小只有200多K

nginx gzip压缩的更多相关文章
- Nginx Gzip 压缩配置
Nginx Gzip 压缩配置 随着nginx的发展,越来越多的网站使用nginx,因此nginx的优化变得越来越重要,今天我们来看看nginx的gzip压缩到底是怎么压缩的呢? gzip(GNU-Z ...
- 13 nginx gzip压缩提升网站速度
一:nginx gzip压缩提升网站速度 我们观察news.163.com的头信息 请求: Accept-Encoding:gzip,deflate,sdch 响应: Content-Encoding ...
- Nginx网络架构实战学习笔记(三):nginx gzip压缩提升网站速度、expires缓存提升网站负载、反向代理实现nginx+apache动静分离、nginx实现负载均衡
文章目录 nginx gzip压缩提升网站速度 expires缓存提升网站负载 反向代理实现nginx+apache动静分离 nginx实现负载均衡 nginx gzip压缩提升网站速度 网页内容的压 ...
- Nginx -- Gzip 压缩功能作用
1.对应的压缩参数说明# 开启gzip压缩功能gzip on; # 设置允许压缩的页面最小字节数,页面字节数从header头的Content-Length中获取.默认值是0,不管页面多大都进行压缩,建 ...
- Nginx GZIP 压缩
[ HTTP 开启gzip ] gzip on; // 开启 nginx在线实时压缩数据流: gzip_min_length 1k; // 允许压缩的页面最小字节 gzip_buffers 32k; ...
- nginx gzip压缩配置
gzip(GNU-ZIP)是一种压缩技术.经过gzip压缩后页面大小可以变为原来的30%甚至更小,这样,用户浏览页面的时候速度会块得多.gzip 的压缩页面需要浏览器和服务器双方都支持,实际上就是服务 ...
- nginx gzip 压缩设置
mime.types 中包含所有文件的类型,不知道的可以去里面查询 gzip配置的常用参数 gzip on|off; #是否开启gzip gzip_buffers 32 4K| 16 8K #缓冲( ...
- Nginx的gzip压缩的原理和设置参数
开启Nginx gzip压缩非常简单,达到的效果可以压缩静态文件大小.提高页面访问速度.节省流量和带宽是很有帮助的,也为用户省去了很多流量:唯一的不足就是开启之后服务器这边会增加运算,进行压缩运算处理 ...
- Nginx 开启gzip压缩(图片,文件,css)
1.Vim打开Nginx配置文件 vim /usr/local/nginx/conf/nginx.conf 2.找到如下一段,进行修改 gzip on; gzip_min_length 1k; gzi ...
随机推荐
- GYM 101875 2018 USP-ICMC
3月自训 (1):10/12 A: 题意:每个人可以连边,最远连到第(i+k)%n个人,边权为这个人与另一个人连边距离,求生成一颗最大生成树的权值和是多少 题解:可以证明的是,我们每一个人都向接下来的 ...
- bzoj4810 [Ynoi2017]由乃的玉米田 bitset优化+暴力+莫队
[Ynoi2017]由乃的玉米田 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 917 Solved: 447[Submit][Status][Di ...
- Moodle通过CLI安装
Moodle通过CLI安装 前提:Moodle准备工作已经完成 1) 数据库(及用户) 2) moodledata目录 3) 源代码及站点配置 安装过程 打开终端,或通过Putty或Xshell等软件 ...
- Java多线程之“同步”
好习惯要坚持,这是我第二篇博文,任务略重,但是要坚持努力!!! 1.竞争条件 首先,我们回顾一下<Java核心技术卷>里讲到的多线程的“竞争条件”.由于各线程访问数据的次序,可能会产生讹误 ...
- linux包安装,解压,压缩,包管理,环境变量
linux 包安装,解压,压缩,包管理 centoscentos上有系统包管理器yum yum的配置一般有两种方式,一种是直接配置/etc目录下的yum.conf文件,另外一种是在/etc/yum.r ...
- hdu 4408 Minimum Spanning Tree
Problem Description XXX is very interested in algorithm. After learning the Prim algorithm and Krusk ...
- hdu 4903 The only survival
The only survival http://acm.hdu.edu.cn/showproblem.php?pid=4903 Time Limit: 40000/20000 MS (Java/Ot ...
- 51Nod 1094 和为k的连续区间 | 水
Input示例 6 10 1 2 3 4 5 6 Output示例 1 4 #include "cstdio" #include "algorithm" #in ...
- Independence.
It's not giving up, it's letting go, and moving to a better place. I will survive and be the one who ...
- centos6.8使用脚本一键搭建apache+svn服务
服务器环境: 脚本如下: #!/bin/bash yum install wget -y mv /etc/yum.repos.d/*.repo /tmp wget -O /etc/yum.repos. ...