Nginx安装http_image_filter_module图片裁剪模块
2016-09-30 23:29
1611 查看
http_image_filter_module用来裁剪图片的,是nginx自带模块,默认不会开启
开启该模块需要在编译时要带上参数
这里比如在tomcat服务器下放个 test 目录存放图片,则可以 http://ip:8080/test/234241.jpg 这样访问图片,安装裁剪模块后可以 http://ip:8080/test/234241_100x100_80.jpg 自动裁剪原图。
image_filter_module 没有真正生成裁剪/缩放后的图片,而是通过 Nginx 直接输出的,这样每次请求或缓存过期后都需要重新裁剪/缩放,会增加 Nginx 负担
需要下载的软件及模块:nginx-1.10.1.tar.gz,LuaJIT-2.0.3.tar.gz,pcre-8.35.tar.gz
配置变量
执行下面命令
[参考资料]
丁丁的开发日记
开启该模块需要在编译时要带上参数
--with-http_image_filter_module
这里比如在tomcat服务器下放个 test 目录存放图片,则可以 http://ip:8080/test/234241.jpg 这样访问图片,安装裁剪模块后可以 http://ip:8080/test/234241_100x100_80.jpg 自动裁剪原图。
image_filter_module 没有真正生成裁剪/缩放后的图片,而是通过 Nginx 直接输出的,这样每次请求或缓存过期后都需要重新裁剪/缩放,会增加 Nginx 负担
需要下载的软件及模块:nginx-1.10.1.tar.gz,LuaJIT-2.0.3.tar.gz,pcre-8.35.tar.gz
yum安装nginx依赖模块
pcre为了重写rewrite, zlib为了gzip压缩yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel gd-devel
编译安装LuaJIT
tar zxvf LuaJIT-2.0.3.tar.gz sudo make && make install
配置变量
vi /etc/profile export LUAJIT_LIB=/usr/local/lib export LUAJIT_INC=/usr/local/include/luajit-2.0
执行下面命令
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf ldconfig
编译安装 nginx
将pcre-8.35.tar.gz放到/usr/local下解压
tar zxvf pcre-8.35.tar.gz tar zxvf nginx-1.10.1.tar.gz cd nginx-1.10.1 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-pcre=/usr/local/pcre-8.35 make make install make clean
文件配置
在/usr/local/nginx/servers新建文件 image.test.com
server { listen 80; server_name image.test.com; index index.html index.htm index.php; location / { proxy_pass http://ip:8080/test/; } //裁剪图片尺寸 filename_100x100.jpg location ~* .*_(\d+)x(\d+)\.(JPG|jpg|gif|png|PNG)$ { set $img_width $1; set $img_height $2; rewrite ^(.*)_\d+x\d+.(JPG|jpg|gif|png|PNG)$ /test$1.$2 break; image_filter resize $img_width $img_height; image_filter_buffer 10M; proxy_pass http://ip:8080; } //裁剪图片尺寸并压缩 filename_100x100_80.jpg location ~* .*_(\d+)x(\d+)_(\d+)\.(JPG|jpg|gif|png|PNG)$ { set $img_width $1; set $img_height $2; set $img_quality $3; rewrite ^(.*)_\d+x\d+_\d+.(JPG|jpg|gif|png|PNG)$ /test$1.$2 break; image_filter resize $img_width $img_height; image_filter_buffer 10M; image_filter_jpeg_quality $img_quality; proxy_pass http://ip:8080; } }
image_filter_jpeg_quality:设置jpeg图片的压缩质量比例(官方最高建议设置到95,但平时75就可以了);
image_filter_buffer:限制图片最大读取大小,默认为1M;
image_filter_transparency:用来禁用gif和palette-based的png图片的透明度,以此来提高图片质量。
[参考资料]
丁丁的开发日记
相关文章推荐
- nginx图片过滤处理模块http_image_filter_module安装配置笔记
- nginx图片过滤处理模块http_image_filter_module安装配置笔记
- nginx图片过滤处理模块http_image_filter_module安装配置
- nginx图片过滤处理模块http_image_filter_module安装配置笔记
- Nginx图片剪裁模块探究 http_image_filter_module
- Nginx http_image_filter_module 图片缩放模块
- 关于nginx的ngx_http_image_filter_module裁剪图片后方向改变的解决方案
- nginx 动态缩略图模块安装(ngx_http_image_filter_module)
- 安装成功的nginx,如何添加未编译安装模块(非覆盖安装http_image_filter_module)
- nginx图片过滤处理模块http_image_filter_module
- 安装成功的nginx,如何添加未编译安装模块(非覆盖安装http_image_filter_module)
- Nginx编译安装第三方模块http_substitutions_filter_module
- Nginx之http_image_filter_module模块使用
- Nginx的 http_image_filter_module 模块使用说明
- LNMP系列——利用nginx 的http_image_filter_module 搭建图片网关
- FastDFS组合nginx的http_image_filter_module建立的图片服务器-分布式文件系统(FastDFS)-ChinaUnix.net
- 利用 Nginx 的 ngx_http_image_filter_module 做实时的图片缩略图
- Nginx之http_image_filter_module模块使用
- Nginx图片剪裁模块探究 http_image_filter_module 推荐
- Nginx之http_image_filter_module模块使用