Last active
September 26, 2016 06:25
-
-
Save Samorai/aeb33fd2b0fcda536e10 to your computer and use it in GitHub Desktop.
Nginx: cache and resize files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
location /resize { | |
gzip on; | |
gzip_static on; | |
gzip_http_version 1.1; | |
gzip_vary on; | |
gzip_comp_level 1; | |
gzip_proxied any; | |
gzip_buffers 128 32k; #my pagesize is 4 | |
gzip_disable "MSIE [1-6]\.(?!.*SV1)"; | |
gzip_min_length 1000; | |
gzip_types *; | |
expires 30d; | |
access_log /dev/null; | |
alias /tmp/nginx/resize; | |
if ($uri ~* "^/resize_(\d+)x(\d+)/(.*)" ) { | |
set $width $1; | |
set $height $2; | |
set $image_path $3; | |
set $quality 100; | |
set $dimens "_$1x$2"; | |
} | |
if ($uri ~* "^/resize/(.*)" ) { | |
set $image_path $1; | |
} | |
set $image_uri image_resize/$image_path?width=$width&height=$height&quality=$quality; | |
resolver 8.8.8.8; | |
if (!-f $request_filename) { | |
proxy_pass $scheme://127.0.0.1/$image_uri; | |
break; | |
} | |
proxy_cache_valid 200 30d; | |
proxy_cache_valid any 1m; | |
proxy_store /tmp/nginx/resize$dimens/$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 ###ROOT DIRECTORY HERE###; | |
image_filter resize $arg_width $arg_height; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment