Question

Host multiple node.js applications on Digital Ocean using NginX

  • Posted on August 31, 2014
  • jlim8612Asked by jlim8612

I followed this guide to setup a reverse proxy for my node apps - https://www.digitalocean.com/community/tutorials/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab

The gist of it is to include this configuration

server {
    listen 80;

    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:3000;
        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;
    }
}

This seems to work for the root location - / , but fails when I add a custom folder path. Something like this -

server {
    listen 80;

    server_name your-domain.com;

    location /test/ {
        proxy_pass http://localhost:3000;
        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;
    }

}

My aim is to navigate to my site using example.com/test/ , so that I can list multiple paths for programs. The error I get from chrome is cannot GET example.com/test/


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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

this answer is not for the nginx way. check out [https://github.com/substack/bouncy] or [https://www.npmjs.com/package/bouncy] if you want to do it the Node/Express way. assume port 8001 is node app A and 8002 is node app B. change to port 80 and nodemon this file.

var bouncy = require(‘bouncy’);

var server = bouncy(function (req, res, bounce) { if (req.headers.host === ‘beep.example.com’) { bounce(8001); } else if (req.headers.host === ‘boop.example.com’) { bounce(8002); } else { res.statusCode = 404; res.end(‘no such host’); } }); server.listen(80)

This comment has been deleted

This comment has been deleted