nginx使用http_image_filter_module图片加水印
- 下载nginx版本 >= 1.11.6
- 下载 http_image_filter_module github下载http_image_filter_module
- 解压nginx-xxx.xx.x.tar.gz
tar -zxvf nginx-xxx.xx.x.tar.gz
- 解压nginx-image-filter-watermark-master.zip
unzip nginx-image-filter-watermark-master.zip
- 将
nginx-image-filter-watermark-master
中解压的http_image_filter_module.c
文件覆盖到nginx
的解压目录下nginx/src/http/modules/http_image_filter_module.c
- 安装nginx依赖
yum -y install gcc openssl openssl-devel pcre pcre-devel perl-ExtUtils-Embed zlib zlib-devel gcc-c++ autoconf automake libxml2 libxml2-dev libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data
- 在
nginx-xxx.xx.x
解压目录 执行./configure --with-http_image_filter_module make make install
- 在 nginx
/usr/local/nginx/conf/nginx.conf
中设置location /img/ { image_filter watermark; #开启水印 image_filter_watermark "/mnt/web/shuiyin.png"; #水印文件位置 (绝对路径) image_filter_watermark_position bottom-right; #水印位置 image_filter_jpeg_quality 95; #图片质量 image_filter_buffer 20M; #缓存 image_filter_watermark_width_from 40; # 打水印的图片最小宽度,只有大于这个宽度的才会打水印 image_filter_watermark_height_from 40; #打水印的图片最小高度,只有大于这个高度的才会打水印 }
- 设置环境变量
vim /etc/profile
文件末尾加上
执行export PATH=/usr/local/nginx/sbin:$PATH
source /etc/profile
- 启动nginx