8814be0ab2a07c1996ea32aa4ecef402af38044e
By:
ccuilla

Multi-droplet architecture same domain

February 2, 2016 947 views
DigitalOcean DNS Ubuntu

Maybe this is not the best (right?) approach, but I'm investigating the following setup and wondering if this is possible with Digital Ocean Droplets:

Imagine a base domain: foo.com

Now I want to be able to support multiple apps like this:

foo.com/blog (Wordpress, probably on its own Droplet)
foo.com/app (probably Node or something, on its own Droplet)
foo.com/app/v1 (probably Node or something, on its own Droplet)
foo.com/app/v2 (probably Node or something, on its own Droplet)

The basic question here is can I setup different droplets for these different paths and do the routing/redirection from the main entry droplet running foo.com?

The alternative approach is to do something like this:

foo.com (Droplet 1)
blog.foo.com (Droplet 2 - Wordpress)
app.foo.com
v1.app.foo.com (Droplet 3 - Node)
v2.app.foo.com (Droplet 4 - Node)

Anyone done anything like this? Any thoughts on it?

4 Answers

If I were to do this I would likely set up a droplet with NGINX that responds at foo.com and set up multiple Location blocks in the server block for a proxy_pass configuration to each service:

Example:

server {
       listen   80; 

        root /var/www/; 
        index index.php index.html index.htm;

        location /blog {

        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://blog.foo.com;

         }

        location /app {

        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://app.foo.com;

         }
}

This hasn't been tested on nginx but should give you what you need. I do not know if it would be possible to have something at /app as well as something at /app/v1 but this would support /app/v1 and /app/v2 without content in /app.

Have another answer? Share your knowledge.