首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何配置nginx http图片过滤模块?

如何配置nginx http图片过滤模块?
EN

Stack Overflow用户
提问于 2018-08-15 18:50:18
回答 1查看 1.5K关注 0票数 0

我有两台服务器,需要配置nginx http_image_filter模块。

第一个服务器配置:

代码语言:javascript
运行
复制
server {
  listen 80;
  server_name image.site.com;
  access_log      /var/log/nginx/image.site.com-access.log;
  error_log       /var/log/nginx/image.site.com-error.log;


  location / {
    proxy_pass http://192.168.1.4;
    }
}

192.168.1.4上的配置为:

代码语言:javascript
运行
复制
server {
  listen 80;
  server_name image.site.com;
  access_log      /var/log/nginx/image.site.com-access.log;
  error_log       /var/log/nginx/image.site.com-error.log;
  root /home/zulu/img/RU/;

location ~ "/img/RU/(.*[^0-9])([0-9]+)x([0-9]+).png$" {
  set $image $1;
  set $width $2;
  set $height $3;
  image_filter resize $width $height;
  }
}

当我转到image.site.com/img/RU/image.png时,它不工作

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-29 14:24:06

这是正确的配置:

代理

代码语言:javascript
运行
复制
server {
  listen 80;
  server_name image.site.com;
  access_log      /var/log/nginx/image.site.com.log;
  error_log       /var/log/nginx/image.site.com-error.log;

  location / {
    proxy_pass http://192.168.151.4;
    }

    proxy_cache images;
    proxy_cache_lock on;
    proxy_cache_valid 30d;
    proxy_cache_use_stale error timeout invalid_header updating;
    expires 30d;
}

和镜像服务器

代码语言:javascript
运行
复制
server {
  listen 80;
  server_name image.site.com;
  access_log      /var/log/nginx/image.site.com.log;
  error_log       /var/log/nginx/image.site.com-error.log;
  root /var/www/files/update/ServiceLogo/;
  image_filter_buffer 50M;

  location ~ ^/(?<width>\d+)x(?<height>\d+)/(?<name>.*)$ {
    image_filter resize $width $height;
    alias /var/www/files/update/ServiceLogo/$name;
  }

  location ~ ^/c/(?<width>\d+)x(?<height>\d+)/(?<name>.*)$ {
    image_filter crop $width $height;
    alias /var/www/files/update/ServiceLogo/$name;
  }

  location ~ ^/users/(?<width>\d+)x(?<height>\d+)/(?<name>.*)$ {
    image_filter resize $width $height;
    alias /var/www/files/update/personDocs/$name;
  }

  location ~ ^/cusers/(?<width>\d+)x(?<height>\d+)/(?<name>.*)$ {
    image_filter crop $width $height;
    alias /var/www/files/update/personDocs/$name;
  }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51857328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档