nginx 이미지 자동 리사이즈 설정
nginx 설치 할 때 ngx_http_image_filter_module
필요
location /pics {
alias /var/www/pics;
set $width 500;
set $height 500;
set $dimens "";
if ($uri ~* "^/pics_(\d+)x(\d+)/(.*)" ) {
set $width $1;
set $height $2;
set $image_path $3;
set $demins "$1x$2";
}
if ($uri ~* "^/pics/(.*)" ) {
set $image_path $1;
}
set $image_uri image_resize/$image_path?width=$width&height=$height;
if (!-f $request_filename) {
proxy_pass http://192.168.0.100/$image_uri;
break;
}
proxy_store /var/www/pics/$demins/$image_path;
proxy_store_access user:rw group:rw all:r;
proxy_temp_path /tmp/images;
proxy_set_header Host $host;
}
location /image_resize {
alias /var/www/pics;
image_filter resize $arg_width $arg_height;
image_filter_jpeg_quality 75;
image_filter_buffer 5m; // 최대 이미지 용량 기본은 1m
# allow 127.0.0.0/8;
# allow 192.168.0.1/32;
# deny all;
}
}
참고
http://nginx.org/en/docs/http/ngx_http_image_filter_module.html
원래 이미지
http://192.168.0.100/pics/sbg.png
썸네일 이미지
http://192.168.0.100/pics_500x500/sbg.png