Fastdfs安装_nginx进行图片动态压缩

说明

1.因为上传的图片较大,部分页面直接引用图片地址,则造成页面加载缓慢问题。
2.考虑到服务器空间问题,我们没有进行上传缩略图。仅仅是上传了原图
3.为了优化页面加载图片的时间问题,所以对图片进行动态缩放。

PS:如果访问量较高,建议进行存储缩略图

图片缩放采用nginx的 http_image_filter_module 详细见:http://nginx.org/en/docs/http/ngx_http_image_filter_module.html

安装准备

  • 图片缩放依赖于 gdlib

下载地址: https://libgd.github.io/ https://github.com/libgd/libgd/releases/download/gd-2.2.4/libgd-2.2.4.tar.gz
下载后,进入目录,依次执行

1./configure 2sudo make 3sudo make install

安装nginx module

1.编译

因为nginx 自带该 module,只需要编译nginx启用即可

1./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre=/soft/pcre-8.35 --add-module=/soft/fastdfs-nginx-module-master/src --with-http_image_filter_module 2 3sudo make ; 4sudo make install;

2.修改配置文件

修改 nginx.conf文件

  • 说明:image_filter 的resize 中,支持 - 变量。
  • 原文提示“proportionally reduces an image to the specified sizes. To reduce by only one dimension, another dimension can be specified as “-”. In case of an error, the server will return code 415 (Unsupported Media Type). Parameter values can contain variables. When used along with the rotate parameter, the rotation happens after reduction.”
1location ~/group1/M00/(.*)\.(jpg|jpeg|gif|png) { 2 root /home/administrator/fastdfs/data; 3 ngx_fastdfs_module; 4 set $w "-"; 5 if ($arg_w != "") { 6 set $w $arg_w; 7 } 8 image_filter resize $w $w; 9 image_filter_buffer 2M; 10} 11

完成

可以访问:http://192.168.31.95/group1/M00/00/00/wKgfX1k_RqiACmScAASQWK7MiFY632.jpg?w=200 即可看到效果啦

可能会遇见的问题

  1. undefined reference to gdImageJpegPtr'或 undefined reference to gdImagePngPtr' 或者 undefined symbol: gdImageCreateFromJpegPtr

需要安装jpeg的库 。安装完毕后,重新编译nginx 。
下载地址:http://web.mit.edu/wwinnie/MacData/afs/athena/system/i386_deb50/os/usr/share/doc/libgd2-noxpm/README.html

  1. 如果提示“ gd_gd2.c:213:40: error: ‘INT_MAX’ undeclared (first use in this function) if (*ncx <= 0 || *ncy <= 0 || *ncx > INT_MAX / *ncy) {”

网络上找到一个偏方(我不会c): 可以修改文件 src/gd_gd2.c. , 添加 include <limits.h> 然后 sudo make

1#include <math.h> 2#include <limits.h> 3#include <string.h>
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

Fastdfs安装_nginx进行图片动态压缩 - HelloWorld