0

Let's say I had a few separate HTTP servers made in node, each with a unique ID attached to them. Is there any way to access them with request URLs based on that id? For example:

Server ifjw48n: accessible via http://example.com/ifjw48n

Server ty58u7e: accessible via http://example.com/ty58u7e

3
  • Probably with a proxy server doing routing to each particular nodejs instance. I am assuming that each of your http servers is listening on a different port. Commented Feb 25, 2015 at 3:45
  • If you were using a framework such as express, you could send each route to a completely separate module, yet use the same server (if that's not doable, yes, use a proxy but that simply increases overhead). What is the necessity of running two servers for what appears to be the same domain in your example? Commented Feb 25, 2015 at 3:50
  • I'm trying to create "private" servers for different clients on a specific request, such as: Client make a POST request containing a variable, and a webserver is created using that variable in it. Commented Feb 25, 2015 at 16:19

1 Answer 1

2

It appears you can do this with nginx used as a routing proxy. Similar question in a different stackexchange forum answered here: Routing to various node.js servers on same machine.

From that answer, here's a sample config that does routing based on the URL:

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;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

@skeeballassault - does this answer work for you? Anything else you need?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.