nginx添加图片处理工具

nginx添加图片处理工具

  • 查看nginx信息 nginx -V,下载相同版本nginx解压并编译
  • configure编译时追加参数--with-http_image_filter_module,执行make命令
  • 备份原来nginx可执行文件,复制objs目录的nginx文件,到nginx sbin 目录
  • 配置 nginx.conf

location ~ .*\.(gif|jpg|jpeg|png)?filter$ {
  # 图片默认宽度
  set $w -;
  # 图片默认高度
  set $h -;
  if ($arg_w != "") {
    set $w $arg_w;
  }
  if ($arg_h != "") {
    set $h $arg_h;
  }
  image_filter resize  $w $h;
  image_filter crop $w $h;
  image_filter_jpeg_quality 75;
  image_filter_buffer  10M;
  try_files /$1.$2 /notfound.jpg;
  expires 30d;
  access_log off;
}

location ~* /(.+)\.(jpg|jpeg|gif|png)!(\d+)x(\d+)$ {
  set $w $3;
  set $h $4;
  image_filter resize  $w $h;
  image_filter crop $w $h;
  image_filter_jpeg_quality 75;
  image_filter_buffer  10M;
  try_files /$1.$2 /notfound.jpg;
  expires 30d;
  access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico|woff2|svg)$ {
  expires 30d;
  access_log off;
}

posted @ 2021-09-09 16:49  小叮当的肚兜  阅读(83)  评论(0编辑  收藏  举报