Question

Two different Node apps on sub domains in a single droplet.

I want to run two different apps on two different sub domains under one droplet.


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.

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
February 14, 2018
Accepted Answer

In order to run two Node apps on a single Droplet, you’ll need to configure a reverse proxy to direct requests to the correct applications. Nginx is a popular choice for doing this. Each app will need to be configured to listen on a separate port locally while Nginx will listen publicly with a “server block” for each app. A quick minimal example of the Nginx configuration would look like:

server {
    listen 80;

    server_name subdomain1.example.com;

    location / {
        proxy_pass http://localhost:PORT_ONE;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

server {
    listen 80;

    server_name subdomain2.example.com;

    location / {
        proxy_pass http://localhost:PORT_TWO;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Depending on the details of your applications, there may be additional configuration needed. Check out these tutorials for more information. The first covers Nginx server blocks; the second is specifically on using Nginx as a reverse proxy for Node apps:

@asb i did the same config but the sub domain not working. but the ip:port still running right

did it need to setup DNS ??

Try DigitalOcean for free

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

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.