LNMP 安装 http_image_filter_module 模块 并配置使用

  1. 进入lnmp目录, 编辑 lnmp.conf 文件
cd ./lnmp1.6
vim lnmp.conf

添加模块

Nginx_Modules_Options='--add-module= --with-http_image_filter_module'

在这里插入图片描述

  1. 启动lnmp升级脚本 使用跟你现在的nginx 一样的版本就可以了
# 查看Nginx版本
nginx -v
./upgrade.sh

在这里插入图片描述

  1. 安装完毕后,查看模块是否已经安装成功
nginx -V

在这里插入图片描述

  1. 进入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
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值