So I've set up NGINX to serve static websites per user on GNU/Linux Debian 8, using the following naming convention: http://domain/~username. Each user's public web folder is located in their respective home directory, and that's also where they will be expected to keep their Node.js projects.


This is all well and good, however, how can I keep different users from starting projects that use colliding port numbers on the same domain? Or more succintly, how can I force each user to use just one unique port number in Node.js? Or do I even need to? Can a user's instance of Node.js be captured somehow, and then translated into something adhering to the above naming convention? If so, how?

Example: If user JSmith makes a website using Node.js and runs it, the website should be published to www.example.com/~jsmith no matter what other domain or port settings JSmith used in his Node.js application.

1 Answer 1


Node.js generally acts as its own HTTP server, right? So if they all execute their node.js projects on that same Ubuntu server, and assuming they don't all have root privs, then they'll be opening TCP listener ports in the ephemeral port range (49152–65536) on that server's IP address(es). Ubuntu's Linux kernel's TCP/IP stack will make sure no two active processes can open the same port at the same time. To connect to their node.js app instances, they will have to connect to http://www.example.com:port/ (where port is whatever port they were able to open).

  • Thanks for the input. That won't do, sadly, since it'll be hit or miss for my users, and most of all, for my server. I wonder, though, if a reverse firewall might do it, with a unique preset port open for each user, for that spesific use. I could possibly also just reverse proxy NGINX with a user regex, though I'm not sure how I'd configure it to have user spesific ports.
    – Kebman
    Commented Mar 4, 2017 at 23:43

You must log in to answer this question.

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