Nginx 圖片文件配置水印

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;
    }

    #根據(jù)給定的長寬生成縮略圖
    image_filter resize $h $w;
    #原圖最大2M,要裁剪的圖片超過2M返回415錯誤,需要調(diào)節(jié)參數(shù)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文件夾,否則出現(xiàn)415 錯誤
#則必須存在的路徑為:/data/testfile/img/  
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,678評論 19 139
  • Page 1:nginx 服務(wù)器安裝及配置文件詳解 CentOS 6.2 x86_64 安裝 nginx 1.1 ...
    xiaojianxu閱讀 8,694評論 1 41
  • 一場雨 就帶來了整個秋天 你蹣跚的走來 走在我模糊的視線里 關(guān)切的眼神,佝僂的背 家,壓彎了你的脊梁 兒女,溫暖了...
    暖意人生1閱讀 257評論 6 13
  • (湘楚行) 文/菊 峽谷空洞懸, 幽壑飛流濺。 游道潺湲瀑掛簾, 瀲滟清波堰。 吳戰(zhàn)闖王鞭, 石破巖叢貫。 峭壁千...
    斌之志閱讀 454評論 12 16
  • 沒有文筆,寫不出好文,甚至高中寫篇作文都要絞盡腦汁編一下午的我,加入簡書,是因為爺爺。 腦血栓,糖...
    Chen豆豆閱讀 370評論 0 0

友情鏈接更多精彩內(nèi)容