Skip to content

Instantly share code, notes, and snippets.

@heynemann
Created August 13, 2012 14:30
Show Gist options
  • Save heynemann/3341234 to your computer and use it in GitHub Desktop.
Save heynemann/3341234 to your computer and use it in GitHub Desktop.
nginx conf for thumbor
upstream thumborbe {
server thumbor.myhost.com:8090 ;
server thumbor.myhost.com:8091 ;
server thumbor.myhost.com:8092 ;
server thumbor.myhost.com:8093 ;
server thumbor.myhost.com:8094 ;
server thumbor.myhost.com:8095 ;
}
location ~* "^/.{28}/.*(jpg|jpeg|gif|png)(#.*)?$" {
root /path/to/your/thumbor/generated/images;
expires 1M;
error_page 404 = @fetch;
}
location @fetch {
internal;
proxy_pass http://thumborbe$request_uri;
}
@sunil05
Copy link

sunil05 commented Mar 4, 2015

@heynemann I have few concerns with method suggested to scale thumbor. They might sound naive but it will be great if someone can clearify or suggest better way.
Since we are pre-deciding the number of processes, how exactly we handle case where not so many process is required? Do we kill the processes and restart them on demand?
And If we get even exceeding requests, shouldn't there should be some way start new process dynamically? (as WSGI does with threads.)

@joanscript
Copy link

@heynemann This is a great conf to use nginx as the web server who serves the images directly if they are already created. But there is a problem, since for each image thumbor create a new folder, e.g.
Image to be served: /o8cKe6jiyqpLjcKN2Osg2da-1Es=/fit-in/640x480/image.jpg
folder created: /o8/ck/o8cKe6jiyqpLjcKN2Osg2da-1Es=/

How do we point nginx to this dynamic folders?
Do u know what I mean?

Thanks in advance.

@joanscript
Copy link

I think I got the answer, just using the regular expressions of the same nginx:

    location ~* "^/(..)(..)(.){24}/.*(jpg|jpeg|gif|png)(#.*)?$" {
        root        /path/to/your/thumbor/generated/images/$1/$2;
        expires     1M;

        error_page  404 = @fetch;
    }

@eduherraiz
Copy link

I wrote another nginx config, based on this gist, that works in the case of external urls.
Take a look on this gist: https://gist.github.com/eduherraiz/9618f2dee94d7876e735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment