nginx 動態縮略圖配置記錄
阿新 • • 發佈:2018-04-26
res AC inotify write home lis $1 nbsp 同時
最近公司商城的圖片嚴重影響到了網站的正常訪問,為了盡快解決這個問題,采用 圖片動態生成的處理方式。這裏用到了nginx的 http_image_filter_module 模塊,安裝nginx的時候需要配置上 --with-http_image_filter_module
同時,把原來放在項目跟目錄下的圖片通過 rsync + inotify 配置 對圖片進行同步,同步到圖片服務器
nginx 配置:
server { listen 80; server_name static.xxxx.com; location ~* /uploads/(.*)_(\d+)x(\d+)\.(jpeg|jpg|png|gif)$ { root /home/wwwroot; set $h $2; set $w $3; if ($h = ‘0‘){ rewrite /uploads/(.*)_(\d+)x(\d+)\.(jpeg|jpg|gif|png)$ /uploads/$1.$4 last; } if ($w = ‘0‘) { rewrite /uploads/(.*)_(\d+)x(\d+)\.(jpeg|jpg|gif|png)$ /uploads/$1.$4 last; } #生成縮略圖 image_filter resize $h $w; image_filter_buffer 5M; error_page 415 /uploads/nopicture.png; try_files /uploads/$1.$4 /uploads/nopicture.jpg; } location ~* /uploads/(\d+){ root /home/wwwroot; } # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } #access_log /home/wwwlogs/static.cwbbc.com.log access; }
nginx 動態縮略圖配置記錄