Last active
August 9, 2016 10:31
-
-
Save recoilme/5bfcf1d558c5e6183bbe9a0a72a0e5d0 to your computer and use it in GitHub Desktop.
This file contains 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
# Nginx image resize + proxy + caching of results. | |
# based on article: http://adw0rd.com/2012/11/10/django-nginx-image/en/ with third party servers support | |
# usage: | |
# http://localhost:8888/resize/365/260/?url=https://meduza.io/image/share_images/32059.png?1470633569#800x420 | |
# http://localhost:8888/crop/365/-/?url=https://meduza.io/image/share_images/32059.png?1470633569#800x420 | |
http { | |
#... | |
proxy_cache_path /usr/local/openresty/nginx/cache levels=1:2 keys_zone=thumb:10m max_size=1G; | |
server { | |
#... | |
location ~ ^/resize/([\d\-]+)/([\d\-]+)/ { | |
#proxy http://nginx.org/ru/docs/http/ngx_http_proxy_module.html | |
resolver 8.8.8.8; | |
proxy_pass $arg_url; | |
#resize http://nginx.org/ru/docs/http/ngx_http_image_filter_module.html | |
image_filter resize $1 $2; | |
image_filter_buffer 2M; | |
#cache http://nginx.org/ru/docs/http/ngx_http_proxy_module.html | |
proxy_cache thumb; | |
proxy_cache_key "$arg_url$document_uri"; | |
proxy_cache_valid 200 1d; | |
proxy_cache_valid any 1m; | |
proxy_cache_use_stale error timeout invalid_header updating; | |
break; | |
} | |
location ~ ^/crop/([\d\-]+)/([\d\-]+)/ { | |
resolver 8.8.8.8; | |
proxy_pass $arg_url; | |
image_filter crop $1 $2; | |
proxy_cache thumb; | |
proxy_cache_key "$arg_url$document_uri"; | |
proxy_cache_valid 200 1d; | |
proxy_cache_valid any 1m; | |
proxy_cache_use_stale error timeout invalid_header updating; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment