Skip to content

Instantly share code, notes, and snippets.

@johnnyt
Created September 20, 2013 18:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnnyt/6642176 to your computer and use it in GitHub Desktop.
Save johnnyt/6642176 to your computer and use it in GitHub Desktop.
Image resizer in NGINX
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
#include mime.types;
#default_type application/octet-stream;
#log_format imageresize '$host $arg_width x $arg_height $arg_url';
#access_log /opt/boxen/homebrew/var/log/nginx/resize.log imageresize;
resolver 8.8.8.8;
resolver_timeout 30s;
sendfile on;
keepalive_timeout 65;
map $arg_width $width {
default 80;
~^[0-9]+$ $arg_width;
}
map $arg_height $height {
default 80;
~^[0-9]+$ $arg_height;
}
server {
listen 80;
server_name localhost;
root /Users/johnnyt/p/mediaforge/ads_japan;
location @missing_image {
try_files /empty.png $uri;
image_filter resize $width $height;
add_header Resize-Status fail;
}
location /resize {
expires off;
set $url $arg_url;
set_unescape_uri $url;
proxy_pass $url;
image_filter resize $width $height;
add_header Resize-Status success;
error_page 404 415 = @missing_image;
}
location / {
root /Users/johnnyt/p/mediaforge/ads_japan;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment