nginx- page compression

1. Why page compression

在实际的企业当中,nginx服务器上的资源要尽可能的占用的空间少一点
实际上信息量大的网页和高清图片占用存储空间是非常大的,这样不利于服务器性能的优化
因此我们要在服务器上面将网页和图片进行压缩,让客户端去下载就可以了

Whether a large or small systems with the site, there is a corresponding image processing, generate thumbnails, add watermark to images, etc., if it comes to the end of APP, this image processing requirements become more important, because in the present situation the client screen sizes, can cause the following problems:

  • Picture too large to APP Load picture slow;
  • Users consume too much traffic

2. To achieve the page compression

Here Insert Picture Description
Nginx configuration file editing services:

vim /usr/local/nginx/conf/nginx.conf		#写入第一行内容和55行
 1 load_module modules/ngx_http_image_filter_module.so;  52         location /download {

 53             #limit_conn addr 1; #只能一个并发,多了会报错
 54             #limit_rate 50k;    #限制带宽,每秒最多50k
 55                 image_filter resize 150 100; #重新调整图片尺寸(像素)
 56 }

nginx -t	#语法检测
nginx -s reload	#在不暂停服务的情况下重新加载

Here Insert Picture Description
Here Insert Picture Description
View original size picture:

cd /usr/local/nginx/html/download/
ls
du -sh	#为32k

Here Insert Picture Description

Testing:
Web Search 172.25.254.1/download/c.jpg-> Press f12-> select network-> Press f5 to refresh -> view picture is compressed to 3.22k

Here Insert Picture Description

Published 175 original articles · won praise 11 · views 6052

Guess you like

Origin blog.csdn.net/weixin_45775963/article/details/104540464