博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx image_filter 配置记录
阅读量:7041 次
发布时间:2019-06-28

本文共 2989 字,大约阅读时间需要 9 分钟。

nginx_image_filter http_image_filter_module配置----------------------------------第一种://官方配置location /img/ {    proxy_pass   http://backend;    image_filter resize 150 100;    image_filter rotate 90;    error_page   415 = /empty;}location = /empty {    empty_gif;}http://nginx.org/en/docs/http/ngx_http_image_filter_module.html#image_filter_webp_quality-----------------------------------第二种://裁剪图片,不存储硬盘访问 http://xxx.com/fanfan_11.jpg@100w_100h_75Q_rhttp://xxx.com/fanfan.jpg@150w_100h_75Q_rhttp://xxx.com/img/fanfan.jpg@11w_11_h_80Q_r# 等比缩放图片location ~ (.+)\.(jpg|gif|png)@(\d+)w_(\d+)h_(\d+)Q_r$ {    set $w $3; #宽    set $h $4; #高    set $q $5; #图片质量    image_filter resize $w $h;    image_filter_jpeg_quality $q;    image_filter_buffer 5M;    try_files $1.$2 /img/notfound.jpg;}# 裁剪图片location ~ (.+)\.(jpg|gif|png)@(\d+)w_(\d+)h_(\d+)Q_c$ {    set $w $3; #宽    set $h $4; #高    set $q $5; #图片质量    image_filter crop $w $h;    image_filter_jpeg_quality $q;    image_filter_buffer 5M;    try_files $1.$2 /img/notfound.jpg;}---------------------------------------第三种://保存在磁盘访问 http://xxx.com/image_filter/222.jpg@120w_120h_75Q_r代理到xxx.com/image-resize/image_filter/222.jpg?w=200&h=200&q=75location ~ (.+)\.(jpg|gif|png)@(\d+)w_(\d+)h_(\d+)Q_([rc])$ {        # 方便调试    error_log  /usr/local/var/logs/nginx/xxx.com.imagefilter.error.log  debug;    # 限制referer,防盗链    # valid_referers xxx.com;#domain modify    # if ($invalid_referer) {return 404;}     set $w $3; #宽    set $h $4; #高    set $q $5; #图片质量    set $type $6;    set $image_path  $1.$2; #真实图片地址    set $cache_path  $1_$3w_$4h_$5Q_$6.$2;  #临时文件地址    if ($type = 'r') {        set $type 'image-resize';    }    if ($type = 'c') {        set $type 'image-crop';    }    set $image_uri  /$type$image_path?w=$w&h=$h&q=$q;    if (-f $document_root$cache_path) {        rewrite (.+)\.(jpg|gif|png)@(\d+)w_(\d+)h_(\d+)Q_([rc])$ $1_$3w_$4h_$5Q_$6.$2;        break;    }    if (!-f $document_root$cache_path) {        # proxy_pass http://$server_name.$image_uri;        # 必须填写ip,填写域名的话,nginx在启动的时候会检测域名,解析DNS,启动后,在修改域名的解析是不生效的        # 实际上,本机填写域名报500不生效,估计是DNS设置不对,会在server下添加        # resolver 127.0.0.1 valid=300s;        proxy_pass http://127.0.0.1$image_uri;        break;    }    proxy_store $document_root$cache_path;    proxy_store_access user:rw group:rw all:r;    proxy_temp_path  /tmp/images;    proxy_set_header Host $host;    expires  10d; # 设置图片过期时间10天}location ~ /image-resize(.+)\.(jpg|gif|png) {    rewrite /image-resize(.+)\.(jpg|gif|png)$ $1.$2 break;    image_filter resize $arg_w $arg_h;    image_filter_jpeg_quality $arg_q;    image_filter_buffer 5M;    try_files $1.$2 /img/notfound.jpg;}location ~ /image-crop(.+)\.(jpg|gif|png) {    rewrite /image-crop(.+)\.(jpg|gif|png)$ $1.$2 break;    image_filter crop $arg_w $arg_h;    image_filter_jpeg_quality $arg_q;    image_filter_buffer 5M;    try_files $1.$2 /img/notfound.jpg;}https://blog.wangjunfeng.com/archives/669

 

转载于:https://www.cnblogs.com/fanfan259/p/8243875.html

你可能感兴趣的文章
再谈swap
查看>>
文本处理三剑客之-sed基础用法
查看>>
宏正ATEN发行全球首款Cat 5双滑轨19寸LCD KVM切换器
查看>>
consui(二)集群配置
查看>>
Windows Cluster 常用命令
查看>>
AndroidStudio生成jar、so、aar以及上传远程库jcenter
查看>>
Redis 过期键的设置、获取和删除过期时间
查看>>
我的友情链接
查看>>
word,excel,网页上如何打x的n次方
查看>>
Cacti(系统监控)
查看>>
Ubuntu 12.04 修改/etc/resolv.conf重启后还原成修改前状态解决办法
查看>>
我的友情链接
查看>>
JavaSE 学习参考:访问修饰符
查看>>
concat的使用
查看>>
强制初始化Bean
查看>>
微信网页开发之创建Controller(三)
查看>>
SAP GUI里Screen Painter的工作原理
查看>>
TensorFlow官方文档解释关于TensorFlow的一些常见问题
查看>>
Python基础总结成千行代码,让Python入门更简单!
查看>>
【Postfix】利用postal进行Postfix的压力测试
查看>>