Question

One droplet to manage forwarding to other droplets

Hi all,

I am after some advice on best way to achieve the following.

We will have several droplets, each created from the market place ‘Docker’ image and each will have a service running from a docker container on different port numbers (see below).

Droplet 1

localhost:8017

localhost:9017

Droplet 2

localhost:8018

localhost:9018

…what I was hoping to achieve was to have another droplet, running something like Nginx (open to recommendations), to forward all traffic for each domain to the relevant service droplet and port number.

forwardingDroplet port 443

service1.domain.com forwards to droplet 1 on port 8017

service1-sandbox.domain.com forwards to droplet 1 on port 9017

service2.domain.com forwards to droplet 2 on port 8018

service2-sandbox.domain.com forwards to droplet 2 on port 9018

…this forwarding/reverse proxy droplet would also need to, ideally, manage Lets Encrypt certificates.

I currently have each droplet running Nginx locally with reverse proxy in place, but interested in how the above could be implemented so we only have one droplet directly public facing and one place to manage the forwarding/reverse proxy.

Any advice/input greatly appreciated, K…


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
January 14, 2023

Hi there,

Indeed, Nginx sounds like a good option.

What you could do is to setup an Nginx server block for each of your domain names with the corresponding reverse proxy rules.

For example:

  • In /etc/nginx/sites-available/service1.domain.com:
server{
    listen 80;
    server_name service1.domain.com;
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://your_droplet1_ip:8017;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        # location /overview {
        #     proxy_pass http://your_droplet1_ip:8017$request_uri;
        #     proxy_redirect off;
        # }
    }
}
  • In /etc/nginx/sites-available/service2.domain.com:
server{
    listen 80;
    server_name service2.domain.com;
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://your_droplet2_ip:8018;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        # location /overview {
        #     proxy_pass http://your_droplet2_ip:8018$request_uri;
        #     proxy_redirect off;
        # }
    }
}

And so on for each domain name.

Then you could use Let’s Encrypt to issue a certificate for your domains.

You should be able to also achieve this without the need of a separate Nginx Droplet, you could have the same result with the Nginx installed on the Droplets where you’ve deployed your apps on.

Let me know how it goes and let me know if you have any questions!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.