location ~* /(.+)_(\d+)x(\d+)\.(jpg|gif|png|bmp)$ {
set $h $2;
set $w $3;
if ($h = "0") {
rewrite /(.+)_(\d+)x(\d+)\.(jpg|gif|png|bmp)$ /img/$1.$4 last;
}
if ($w = "0") {
rewrite /(.+)_(\d+)x(\d+)\.(jpg|gif|png|bmp)$ /img/$1.$4 last;
}
#根据给定的长宽生成缩略图
image_filter resize $h $w;
#原图最大2M,要裁剪的图片超过2M返回415错误,需要调节参数image_filter_buffer
image_filter_buffer 2M;
#error_page 415 /img/notfound.jpg;
try_files /$1.$4 /notfound.jpg;
}
这个配置只支持jpg、png、gif。就是不支持bmp
解决办法如下:
-
break;
-
.....................
-
}
-
-
-
static u_char *
-
ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type, gdImagePtr img,
-
int *size)
-
{
-
.....................
-
case NGX_HTTP_IMAGE_BMP:
-
out = gdImageBmpPtr(img, size, -1);
-
failed = "gdImageBmpPtr() failed";
-
break;
-
.....................
-
}
src/http/modules/ngx_http_image_filter_module.c: In function ‘ngx_http_image_source’:
src/http/modules/ngx_http_image_filter_module.c:1082: error: implicit declaration of function ‘gdImageCreateFromBmpPtr’
src/http/modules/ngx_http_image_filter_module.c:1082: error: assignment makes pointer from integer without a cast
src/http/modules/ngx_http_image_filter_module.c: In function ‘ngx_http_image_out’:
src/http/modules/ngx_http_image_filter_module.c:1163: error: implicit declaration of function ‘gdImageBmpPtr’
src/http/modules/ngx_http_image_filter_module.c:1163: error: assignment makes pointer from integer without a cast
make[1]: *** [objs/src/http/modules/ngx_http_image_filter_module.o] Error 1
make[1]: Leaving directory `/usr/local/src/nginx-1.4.7'
make: *** [build] Error 2
我的nginx默认是去 /usr/lib64/下面去找libgd.so,编译安装的时候默认的gd路径是/usr/local/lib/下面,所以nginx平滑升级的时候还是出问题了,还好知道问题在哪
编译gd步奏如下
function gd(){
tar zxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --prefix=/usr/local/webserver/zlib
make && make install
cd ../
tar zxf jpegsrc.v9a.tar.gz
cd jpeg-9a/
./configure --prefix=/usr/local/webserver/jpeg9 -enable-shared -enable-static
make && make install
cd ../
tar zxf libpng-1.6.12.tar.gz
cd libpng-1.6.12
./configure --prefix=/usr/local/webserver/png
make && make install
cd ../
tar zxf freetype-2.5.3.tar.gz
cd freetype-2.5.3
./configure --prefix=/usr/local/webserver/freetype
make && make install
cd ../
tar zxf libgd-2.1.0.tar.gz
cd libgd-2.1.0
./configure --with-jpeg=/usr/local/webserver/jpeg9/ --with-png=/usr/local/webserver/png/ --with-zlib=/usr/local/webserver/zlib/ --with-freetype=/usr/local/webserver/freetype/
make && make install
cd ../
echo "========successfully install gd==========="
}
源文出处http://www.91cto.cn/post/133.html