nginx ngx_http_image_filter_module 简单试用
nginx包含了一个ngx_http_image_filter_module 模块,我们可以方便的进行图片的缩略图,平时一些简单的功能
已经够用了
环境准备
为了简单使用docker-compose 运行,因为openresty 已经默认集成了这个模块,就不用安装了
- docker-compose 文件
version: "3"
services:
nginx:
image: openresty/openresty:alpine-fat
volumes:
- "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
- "./images/:/opt/img/"
ports:
- "8080:8080"
- nginx conf
主要是加载模块以及配置模块参数,为了简单测试,直接写了固定参数
load_module "modules/ngx_http_image_filter_module.so";
worker_processes 1;
user root;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
lua_code_cache off;
lua_need_request_body on;
gzip on;
resolver 127.0.0.11 ipv6=off;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
gzip_min_length 2k;
gzip_buffers 4 16k;
gzip_comp_level 4;
gzip_types text/plain text/css image/png application/javascript image/jpeg image/gif;
server {
listen 8080;
server_name app;
charset utf-8;
default_type text/html;
location / {
default_type text/plain;
index index.html index.htm;
}
location = /favicon.ico {
root /opt/app/static;
}
location /img/ {
root /opt;
image_filter resize 600 400;
error_page 415 = /empty;
image_filter_jpeg_quality 95;
image_filter_buffer 20M;
}
location = /empty {
empty_gif;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
测试
为了简单,使用数据卷挂载了一个简单的图片目录
- 启动
docker-compose up -d
- 效果
http://localhost:8080/img/index.png
原图信息
缩略图信息
说明
测试使用了很简单的配置,实际上我们可以用这个做好多强大的功能,类似的可以集成thumbor 实现更强大的功能
参考资料
https://www.cnblogs.com/rongfengliang/p/8650784.html
https://github.com/rongfengliang/openresty-image-filter-demo
https://nginx.org/en/docs/http/ngx_http_image_filter_module.html
https://github.com/rongfengliang/mino-thumbor-openresty
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2015-04-15 TaffyDB:开源JavaScript数据库
2014-04-15 html 滚动固定显示js脚本
2014-04-15 asp.net 导出excel的一种方法
2014-04-15 微软通过.NET Native为Windows Store应用提速
2014-04-15 .NET基金会成立