Skip to content

Instantly share code, notes, and snippets.

@Kuznetsov-Ilia
Forked from phpdude/nginx.conf
Created October 28, 2016 15:34
Show Gist options
  • Save Kuznetsov-Ilia/a17f2fba47e2f415ba2112939a5ac372 to your computer and use it in GitHub Desktop.
Save Kuznetsov-Ilia/a17f2fba47e2f415ba2112939a5ac372 to your computer and use it in GitHub Desktop.
Nginx image filter + caching of results.
Nginx image filter + caching of results.
Supports dynamic thumbnails images sizes processing + caching results, simple to use.
Awesome!!!
location /resize {
alias /tmp/nginx/resize;
set $width 150;
set $height 100;
set $dimens "";
if ($uri ~* "^/resize_(\d+)x(\d+)/(.*)" ) {
set $width $1;
set $height $2;
set $image_path $3;
set $demins "_$1x$2";
}
if ($uri ~* "^/resize/(.*)" ) {
set $image_path $1;
}
set $image_uri image_resize/$image_path?width=$width&height=$height;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:8080/$image_uri;
break;
}
proxy_store /tmp/nginx/resize$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 /path/to/media/;
image_filter resize $arg_width $arg_height;
image_filter_jpeg_quality 75;
allow 127.0.0.0/8;
deny all;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment