I'm working on a project similar to Imgur but for clients only. I'm using NGINX as my webserver and PHP-FPM/MYSQL to handle the rest. One speed bump I will eventually run into is running out of server space. I would like the ability to add more storage servers as they are needed. While I understand cloud storage may be the best route for this in my case this isn't an option at the moment.
So let says I have 3 storage servers all running NGINX we'll call them storage1, storage2 and storage3. If I'm serving the requests from a domain such as i.myimagehost.com I need to find a way to tell NGINX where to proxy the reqyest from my PHP-FPM script or MYSQL database.
Another example:
i.imagehost.com/1234.jpg - hosted on storage1
i.imagehost.com/5678.jpg - hosted on storage2
i.imagehost.com/9012.jpg - hosted on storage3
What I'm trying to do is get the server and file location from my database and/or PHP-FPM and have NGINX pass it on via proxy_pass similar to this:
location / {
proxy_pass http://$storage_server.imagehost.com/$path_to_file;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;}
This is just a crude example of what I'm trying to accomplish. Since each image name would be random I wouldn't be able to set key ranges to determine the server. It would need to come from the database. I'm not sure if it's even possible to do it this way but any help would be appreciated.