热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

nginx动态缩略图模块安装(ngx_http_image_filter_module)

nginx的这个模块在之前曾经关注过,因为其效率问题并没有使用(默认是无缓存的,所以使用中要结合slowfs或者varnish使用)。近期,公司大牛们把这个模块的源码进行了修改,想实现图片
nginx的这个模块在之前曾经关注过,因为其效率问题并没有使用(默认是无缓存的,所以使用中要结合slowfs或者varnish使用)。近期,公司大牛们把这个模块的源码进行了修改,想实现图片的动态缩略图显示。老大告之,源码暂时不能开源,这里先记录下配置过程,后续给出使用及测试结果。大家可以google其功能和使用方法。 一.安装支持组件1.安装libjpegwget http://www.ijg.org/files/jpegsrc.v 8a .tar.gztar zxvf jpegsrc.v8a.tar.gz cd jpeg-8a###32位系统###./configure --prefix=/usr/local/jpeg8 --enable-shared --enable-static make;make install###64位系统###CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/jpeg8 --enable-shared --enable-static makemake install 2.安装libpngwget http://sourceforge.net/projects/libpng/files/01-libpng-master/ 1.4.1 /libpng-1.4.1.tar.gz/downloadtar zxvf libpng-1.4.1.tar.gzcd libpng-1.4.1./configuremake;make install 3.安装freetypewget http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz

 

tar xzvf freetype-2.3.5.tar.gzcd freetype-2.3.5./configure --prefix=/usr/local/freetypemakemake install 4.安装zlib wget  http://www.zlib.net/zlib-1.2.3.tar.gztar xzvf zlib-1.2.3.tar.gzcd zlib-1.2.3./configure makemake install 5.安装gdwget http://www.libgd.org/releases/gd-2.0.35.tar.gz.tar zxvf gd-2.0.35.tar.gzcd  gd-2.0.35./configure --with-jpeg=/usr/local/jpeg8 --with-png -with-zlib -with-freetype=/usr/local/freetype 此时make报错:undefined reference to `png_check_sig’ vi gd_png.c文件,将if (!png_check_sig (sig, 8)) { /* bad signature */return NULL;}修改为if (png_sig_cmp (sig, 0, 8)) { /* bad signature */return NULL;}make;make install 二.编译安装nginx此步骤我们简单带过,因为互联网上关于nginx的安装方法太多了在编译nginx时候请指定如下:1. ./configure --prefix=/usr/local/nginx --user=www --group=www  --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module此时make报错:cc1: warnings being treated as errors src/http/modules/ngx_http_image_filter_module.c: In function ‘ngx_http_image_resize’: src/http/modules/ngx_http_image_filter_module.c:814: warning: ‘resize’ is used uninitialized in this function make[1]: *** [objs/src/http/modules/ngx_http_image_filter_module.o] Error 1 make[1]: Leaving directory `/root/nginx-0.8.34' make: *** [install] Error 2 此问题是由于gcc选项中将warning信息当做error处理,导致编译失败。解决办法如下:./configure完之后vi objs/Makefile修改前几行内容如下:CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -g再次make;make install编译得以通过 2.vi /usr/local/nginx/conf/nginx.conf在虚拟主机(server)块中#add;example

location ~* /small/b(\d+)/e(\d+)/(.*)$ {               proxy_pass http://127.0.0.1;               rewrite "/small/b(\d+)/e(\d+)/(.*)$" /$3 break ;               image_filter  dyna_crop;               error_page 415 = /error.jpg;    }                  location = /error.jpg {                root test;   } 3.后续过程mkdir /usr/local/nginx/html/emptytouch  error.jpg此时启动nginx出现报错信息如下:      /usr/local/nginx/sbin/nginx: error while loading shared libraries: libgd.so.2是由于系统并未加载libgd这个模块,那就手动加载吧:直接/sbin/ldconfig再次启动nginx 成功测试:links http://127.0.0.1/snap/d1/e2/image/1.jpg 查看效果注:image/1.jpg为实际存储的图片路径  好了,先说这么多 有时间补充完整

本文出自 “山岳不知” 博客,请务必保留此出处http://alice.blog.51cto.com/707092/310510


推荐阅读
author-avatar
陈杰铭雅意
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有