公司使用fastdfs做爲文件服務,結合nginx實現文件訪問,但原始圖片比較大,須要實現縮略圖的功能,通過一段時間的研究,今天終於實現了,直接貼配置。nginx
server { listen 8888; server_name 192.168.10.10; location ~*group([0-9])/M00/(.*)\.(jpg|gif|png)(_resize_) { #alias /fastdfs/storage/data; ngx_fastdfs_module; set $width $arg_w; set $height $arg_h; rewrite ~*group([0-9])/M00/(.*)\.(jpg|gif|png) group1/M00/$2.$3 break; image_filter crop $width $height; image_filter_buffer 100M; image_filter_jpeg_quality 75; } location ~*group([0-9])/M00/(.*)\.(jpg|gif|png) { #alias /fastdfs/storage/data; ngx_fastdfs_module; } }
訪問方式舉例:code
原圖:http://192.168.10.10:8888/group1/M00/00/12/xxxxxxxxxx.jpgserver
縮略圖地址:http://192.168.10.10:8888/group1/M00/00/12/xxxxxxxxxx.jpg_resize_?w=200&h=200圖片
前提:須要安裝相關模塊it
1.ngx_http_image_filter_moduleio
2.fastdfs-nginx-moduleast