最近在研究nginx在前端中使用最大化,发现了能够很好的处理图片。前端
咱们先来到软件包的地方看到了configure。nginx
咱们先看一下这个模块http_image_filter_module,已是内置模块了,可是须要从新编译一下,添加这个模块。缓存
上图知道了nginx在编译时不会自动构建http_image_filter_module和http_v2_module。因此须要从新编译nginx。服务器
注意:下次研究一下动态模块加载ui
新增长的配置,咱们须要从新编译。spa
./configure --prefix=/usr/local/nginx --with-http_image_filter_module --with-http_v2_module --with-http_ssl_module --with-openssl=/home/soft/openssl-1.1.0f
上面的/usr/local/nginx这个路径是咱们编译以后的包路径。code
发现报错:blog
查找发现:HttpImageFilterModule模块须要依赖gd-devel的支持,可使用yum或apt-get方便地安装,若是未安装回报“/configure: error: the HTTP image filter module requires the GD library.”错误图片
yum install gd-devel 或者apt-get install libgd2-xpm libgd2-xpm-dev
执行成功后:ssl
配置完成后,运行命令
nake
执行成功以后:
这里不要进行make install,不然就是覆盖安装。
(1)而后备份原有已安装好的nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_07_24.bak
(2)关闭nginx,而后将刚刚编译好的nginx覆盖掉原有的nginx
关闭nginx
./nginx -s quit
删除nginx文件
移动编译好的nginx到原有的nginx
cp ./objs/nginx /usr/local/nginx/sbin/
(3)启动nginx
./nginx
location ~* /image/(.+)$ { # 图片服务器端存储地址 alias /home/static/image/$1; # 图片默认宽度 set $width -; # 图片默认高度 set $height -; if ($arg_width != "") { set $width $arg_width; } if ($arg_height != "") { set $height $arg_height; } # 设置图片宽高 image_filter resize $width $height; # 设置nginx读取图片最大buffer image_filter_buffer 10M; # 是否开启图片隔行扫描 image_filter_interlace on; error_page 404 = error.gif; }
还能够配合nginx的缓存使用。
缩放宽为200px:http://static.chengxinsong.cn...
缩放宽为100px:http://static.chengxinsong.cn...