zongyuewang 2019-03-01
nginx搭配fastdfs生成实时缩略图,并加水印
1,需要image_filter模块
2,添加反向代理的upstream模块
3,配置适配fastdfs访问的group正则表达式
4,增加_P1.jpg这种放置刷新方式
5,调试的时候,如果出现莫名奇妙的错误,请试试将location放置到server中的第一处
6,这种生成缩略图采用nginx自带模块,采用GD压缩,也可以使用GM模块,这种需要使用nginx支持lua模块,然后自己写lua表达式
location配置
location ~* /group(\d+)\/M00\/(\w+)\/(\w+)/(.+)\.(jpg|png|jpeg|bmp|tiff|gif|tif|PNG|JPG|JPEG|BMP|TIFF|GIF|TIF)\_P1\.(jpg|png|jpeg|bmp|tiff|gif|tif|PNG|JPG|JPEG|BMP|TIFF|GIF|TIF)$ { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache http-cache; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; proxy_pass http://fdfs_group$1; expires 7d; #ngx_fastdfs_module; #set $w $6; #set $h $7; rewrite /group(\d+)\/M00\/(\w+)\/(\w+)/(.+)\.(jpg|png|jpeg|bmp|tiff|gif|tif|PNG|JPG|JPEG|BMP|TIFF|GIF|TIF)\_P1\.(jpg|png|jpeg|bmp|tiff|gif|tif|PNG|JPG|JPEG|BMP|TIFF|GIF|TIF)$ /group$1/M00/$2/$3/$4.$5 break; # image_filter resize $w $h; image_filter_buffer 20M; image_filter_interlace on; image_filter_jpeg_quality 95; image_filter watermark; image_filter_watermark_width_from 50; image_filter_watermark_height_from 50; image_filter_watermark "/home/image/water/c.png"; image_filter_watermark_position center-center; image_filter resize 238 193; }
upstream 配置
upstream fdfs_group1 { server 10.192.168.0.1:8888 weight=1 max_fails=2 fail_timeout=30s; }