公司使用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