0

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.

i228
  • 1
  • Instead of mapping requests to individual servers could you virtualise the storage in such a way that it looks like a single pool of storage? Are you tied to any particular operating system? – Tim Jun 23 '17 at 18:25
  • Right now I'm using Debian 8. – i228 Jun 23 '17 at 19:03

1 Answers1

1

My apologies, your suggested solution with location queried from the database looks overly complex. From what I understand, it looks like you definitely should want to use some distributed storage solution.
First thing that comes to mind is minio-based S3-like storage and nginx as a reverse proxy. In such a setup minio should work in distributed mode and nginx will handle load balancing. Minio is simple and lightweight enough to bring it up within 30 minutes.

Quick googling gave me exactly that setup:

Actually, it looks very similar to your suggested approach, but all storage-related logic is handled by the minio. Hope it'll help you a little bit!

J''
  • 91
  • 1
  • 6