Nginx 图片文件配置水印

2018-11-14  本文已影响0人  postSuperMan

Nginx conf 配置文件

######################## default ############################
  server {
    listen 8067;
    server_name _;
    access_log /data/wwwlogs/access_nginx.log combined;
    root /data/wwwroot/default;
    index index.html index.htm index.php;
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    location /nginx_status {
      stub_status on;
      access_log off;
      allow 127.0.0.1;
      deny all;
    }
    
    location /img/ {
        image_filter watermark;
        image_filter_watermark "/usr/local/nginx/html/760.png"; #图片水印路径
        image_filter_watermark_position center-center;
    }

   location ~* /img3/(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ {   
    set $h $2;
    set $w $3;
    if ($h = "0") {
        rewrite /img3/(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ /img3/$1.$4 last;
    }
    if ($w = "0") {
        rewrite /img3/(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ /img3/$1.$4 last;
    }

    #根据给定的长宽生成缩略图
    image_filter resize $h $w;
    #原图最大2M,要裁剪的图片超过2M返回415错误,需要调节参数image_filter_buffer 
    image_filter_buffer 4M;  
    
    image_filter_watermark_width_from 15;   # Minimal width (after resize) of when to use watermark
    image_filter_watermark_height_from 15;  # Minimal height (after resize) of when to use watermark
    image_filter_watermark "/usr/local/nginx/html/760.png";
    image_filter_watermark_position center-center;
    
    #error_page  415      /usr/local/nginx/html/760.png;
    try_files /img3/$1.$4  /usr/local/nginx/html/760.png; 
}

参考链接

阿里云:https://yq.aliyun.com/ziliao/29266

注意事项

root /data/testfile;
location /img/ { 
#路径中必须包含img文件夹,否则出现415 错误
#则必须存在的路径为:/data/testfile/img/  
}
上一篇下一篇

猜你喜欢

热点阅读