在 服务器上按装了Nginx的http_image_filter_module模块,用了一下发现还挺方便的,能满足一些简单的图片剪切需求,从安装到配置过程中涉及到编译和Nginx配置还有一点正则方面的知识点,下面是整理的笔记。
安装http_image_filter_module模块
Nginx安装包
给Nginx添加模块支持需要重新编译Nginx,所以先找到系统的Nginx安装包[nginx-x.xx.x.tar.gz],找个作业目录解压
预编译
cd
进到作业目录里的Nginx下面
./configure. --prefix=/安装目录 --with-http_image_filter_module ***
***
是你之前安装上的模块也要加进去,否则会被覆盖丢失。 可以参照使用/usr/local/nginx/sbin/nginx -V
查出来
编译
make
替换正式nginx文件
把编译生成的./objs/nginx
文件 替换你旧的nginx文件
再使用/usr/local/nginx/sbin/nginx -V
查一下
[root@iz2ze4ame76452xz6l5n00z ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.1.1c 28 May 2019
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_image_filter_module - -with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --wit h-http_gzip_static_module --with-http_realip_module --with-http_flv_module --wit h-http_mp4_module --with-openssl=../openssl-1.1.1c --with-pcre=../pcre-8.43 --wi th-pcre-jit --with-ld-opt=-ljemalloc
OK【--with-http_image_filter_module】出现了,说明顺利安装完了
配置http_image_filter_module模块
先来个简单的,复杂的稍后整理一下再加上来
location ~* (.*\.(jpg|gif|png))!(.*)x(.*)$ {
set $width $3;
set $height $4;
rewrite "(.*\.(jpg|gif|png))(.*)$" $1;
}
location ~* /catcat/.*\.(jpg|gif|png)$ {
image_filter resize $width $height;
}
效果演示
http://code.kissbycat.com/catcat/aa.jpg!100x100
http://code.kissbycat.com/catcat/aa.jpg!150x150
http://code.kissbycat.com/catcat/aa.jpg!200x200
http://code.kissbycat.com/catcat/aa.jpg!250x250
http://code.kissbycat.com/catcat/aa.jpg!300x300
怎么样很好玩吧
Comments | NOTHING