Skip to content

Instantly share code, notes, and snippets.

@graymic
Last active August 29, 2015 14:21
Show Gist options
  • Save graymic/76da12dd87e8a3c5c6d4 to your computer and use it in GitHub Desktop.
Save graymic/76da12dd87e8a3c5c6d4 to your computer and use it in GitHub Desktop.
Nginx Image Resizer - GD
server {
server_tokens off;
listen 8880 default_server;
listen [::]:8880 default_server ipv6only=on;
root /data/sites/my-site/;
index index.html index.htm;
server_name my-site.com;
set $width "-";
set $height "-";
if ($arg_w != '') { set $width $arg_w; }
if ($arg_h != '') { set $height $arg_h; }
// Set the location match for the Laravel storage uploads directory...
location ^~ /storage/app/uploads/ {
add_header X-Nginx-Image Resized;
// You may have to compile nginx if this yields no success...
image_filter resize $width $height;
location ^~ /storage/app/uploads/crop {
internal;
alias /data/sites/my-site/storage/app/uploads/;
add_header X-Nginx-Image Cropped;
image_filter crop $width $height;
}
}
// Deny direct access on this port / path.
location / {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment