Skip to content

Instantly share code, notes, and snippets.

@pingwping
Last active May 11, 2017 09:50
Show Gist options
  • Save pingwping/497d94a5cbfb5ac92621525d149fc4a0 to your computer and use it in GitHub Desktop.
Save pingwping/497d94a5cbfb5ac92621525d149fc4a0 to your computer and use it in GitHub Desktop.
resize image according to query string
#
# The image server
#
proxy_cache_path /tmp/nginx-images-cache/ levels=1:2 keys_zone=images:10m inactive=24h max_size=100m;
upstream image_8083 {
server 127.0.0.1:8083 max_fails=3 fail_timeout=2s;
}
server {
listen *:8086;
listen *:80;
# server_name _;
merge_slashes off;
client_max_body_size 4m;
client_body_buffer_size 128k;
chunked_transfer_encoding on;
access_log /var/log/nginx/car_8086.log main;
root /root/image/www;
index index.html;
autoindex on;
location /resize {
alias /tmp/nginx/resize;
index on;
set $width 200;
set $height 150;
if ($uri ~* "^/resize/(\d+)x(\d+)/(.*)" ) {
set $width $1;
set $height $2;
set $image_path $3;
}
set $image_uri $image_path?w=$width&h=$height;
proxy_pass http://127.0.0.1:8087/$image_uri;
proxy_cache images;
proxy_cache_valid 200 24h;
}
location / {
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^(.+)$ /index.html last;
}
location /api {
chunked_transfer_encoding on;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_pass http://image_8083/api;
}
}
server {
# Internal image resizing server.
listen 8087;
# server_name localhost;
root /root/image/www;
merge_slashes off;
location /upload {
alias /root/image/www/upload;
image_filter resize $arg_w $arg_h;
image_filter_jpeg_quality 90;
image_filter_buffer 8M;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment