- 进入lnmp目录, 编辑 lnmp.conf 文件
cd ./lnmp1.6
vim lnmp.conf
添加模块
Nginx_Modules_Options='--add-module= --with-http_image_filter_module'
- 启动lnmp升级脚本
使用跟你现在的nginx 一样的版本就可以了
# 查看Nginx版本
nginx -v
./upgrade.sh
- 安装完毕后,查看模块是否已经安装成功
nginx -V
- 进入nginx 配置目录, 新增一个图片配置文件
cd /usr/local/nginx/conf/vhost/
vim ./images.conf
简单的一个图片配置文件如下
server
{
listen 81;
server_name 192.168.0.204;
index index.html index.htm index.php;
root /home/wwwroot/images;
location ~* /(.+)\.(jpg|jpeg|gif|png)$ {
# 图片默认宽度
set $width -;
# 图片默认高度
set $height -;
if ($arg_width != "") {
set $width $arg_width;
}
if ($arg_height != "") {
set $height $arg_height;
}
# 设置图片宽高
image_filter resize $width $height;
# 设置nginx读取图片最大buffer
image_filter_buffer 20M;
# 是否开启图片隔行扫描
image_filter_interlace on;
error_page 404 = error.gif;
}
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
error_log off;
}
最后访问下原图路径 http://192.168.0.204:81/202004091657506xT528Vd.jpg
效果如下
原图 11.8M
添加参数, 让其缩略 http://192.168.0.204:81/202004091657506xT528Vd.jpg?width=300&height=300