nginx添加图片处理工具
- 查看nginx信息
nginx -V
,下载相同版本nginx解压并编译
configure
编译时追加参数--with-http_image_filter_module
,执行make
命令
- 备份原来
nginx
可执行文件,复制objs
目录的nginx
文件,到nginx
sbin
目录
- 配置
nginx.conf
location ~ .*\.(gif|jpg|jpeg|png)?filter$ {
# 图片默认宽度
set $w -;
# 图片默认高度
set $h -;
if ($arg_w != "") {
set $w $arg_w;
}
if ($arg_h != "") {
set $h $arg_h;
}
image_filter resize $w $h;
image_filter crop $w $h;
image_filter_jpeg_quality 75;
image_filter_buffer 10M;
try_files /$1.$2 /notfound.jpg;
expires 30d;
access_log off;
}
location ~* /(.+)\.(jpg|jpeg|gif|png)!(\d+)x(\d+)$ {
set $w $3;
set $h $4;
image_filter resize $w $h;
image_filter crop $w $h;
image_filter_jpeg_quality 75;
image_filter_buffer 10M;
try_files /$1.$2 /notfound.jpg;
expires 30d;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico|woff2|svg)$ {
expires 30d;
access_log off;
}