公司使用fastdfs作为文件服务,结合nginx实现文件访问,但原始图片比较大,需要实现缩略图的功能,经过一段时间的研究,今天终于实现了,直接贴配置。 server { listen
公司使用fastdfs作为文件服务,结合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; }}
访问方式举例:
原图:http://192.168.10.10:8888/group1/M00/00/12/xxxxxxxxxx.jpg
缩略图地址:http://192.168.10.10:8888/group1/M00/00/12/xxxxxxxxxx.jpg_resize_?w=200&h=200
前提:需要安装相关模块
1.ngx_http_image_filter_module
2.fastdfs-nginx-module