6

I'd like to set up multiple node.js servers on the same machine (but listening on different ports) for different projects (so I can pull any down to edit code without affecting the others). However I want to be able to access these web apps from a browser without typing in the port number, and instead map different urls to different ports: e.g. 45.23.12.01/app -> 45.23.12.01:8001.

I've considered using node-http-proxy for this, but it doesn't yet support SSL. My hunch is that nginx might be the most suitable. I've never set up nginx before - what configuration do I need to do? The examples of config files I've seen only deal with subdomains, which I don't have.

Alternatively, is there a better (stable, hassle-free) way of hosting multiple apps under the same IP address?

2 Answers 2

7

First start with reading the wiki documentation. It's very thorough and includes samples. I won't give you an entire nginx config, but here is the relevant portion to your question.

server {
    listen 80;
    server_name example.com;

    location /foo {
        proxy_pass http://localhost:9000;
    }

    location /bar {
        proxy_pass http://localhost:9001;
    }

    location /baz {
        proxy_pass http://localhost:9002;
    }
}

It should be clear what's going on there. Each location proxies the specified URI to the appropriate node.js backend.

1

nginx might be the way to go. At least, that is what I have running on my server. An example config/description can be found here: https://blog.noort.be/2011/03/07/node-js-on-nginx.html

You basically set up different sites in nginx and each site routes his traffic to a nodejs app running on a different port.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .