Nginx 缩略图
1、安装PRCE
wget --no-check-certificate https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
tar -xzvf pcre-8.40.tar.gz
cd pcre-8.40
./configure --prefix=/usr/local/pcre --enable-utf8 --enable-unicode-properties
make && make install
2、安装GD
yum install gd-devel
3、下载安装Nginx
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar -xzvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/home/visionread/share/nginx2 --with-http_image_filter_module #注意--prefix 目录,这里指nginx编译安装后对目录
make && make install
4、修改nginx.conf
1.http 代码块 新增:
#缓存配置
proxy_cache_path /home/visionread/image_cache levels=1:2 keys_zone=image_cache:10m max_size=10g inactive=3M use_temp_path=on;
2.service 代码块 新增:
location /court/download/downloadFile {
set $image_uri http://clustername/court/download/downloadFile?CaseID=$arg_CaseID&subIndex=$arg_subIndex&fileID=$arg_fileID&subCaseId=$arg_subCaseId;
if ($arg_process_image ~* "(resize|crop),(\d+|-)x(\d+|-)" ){
set $process $1;
set $width $2;
set $height $3;
set $image_uri http://127.0.0.1:8088/image_$process?CaseID=$arg_CaseID&subIndex=$arg_subIndex&fileID=$arg_fileID&subCaseId=$arg_subCaseId&width=$width&height=$height;
}
proxy_cache_revalidate on;
proxy_cache image_cache;
proxy_temp_path /tmp;
proxy_set_header Host $host;
proxy_pass $image_uri;
proxy_hide_header Cache-Control;
add_header Cache-Control "no-cache";
error_page 415 = /empty;
}
location /image_resize {
proxy_pass http://clustername/court/download/downloadFile?CaseID=$arg_CaseID&subIndex=$arg_subIndex&fileID=$arg_fileID&subCaseId=$arg_subCaseId;
image_filter_buffer 10M;
image_filter resize $arg_width $arg_height;
allow 127.0.0.0/8;
deny all;
expires 1s;
add_header Cache-Control "public";
}
location /image_crop {
proxy_pass http://clustername/court/download/downloadFile?CaseID=$arg_CaseID&subIndex=$arg_subIndex&fileID=$arg_fileID&subCaseId=$arg_subCaseId;
image_filter_buffer 10M;
image_filter crop $arg_width $arg_height;
allow 127.0.0.0/8;
deny all;
expires 1s;
add_header Cache-Control "public";
}
location = /empty {
empty_gif;
}
4、验证是否安装成功
./sbin/nginx -V
输出
nginx version: nginx/1.14.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
configure arguments: --prefix=/home/visionread/share/nginx2 --with-http_image_filter_module
作者:崔启旭 创建时间:2023-04-03 16:04
更新时间:2024-11-15 23:02
更新时间:2024-11-15 23:02