Sebastian
Sebastian

Reputation: 377

webserver node.js as non root user

I'm a Linux beginner and have a Linux Ubuntu 12.04 server. I've installed node.js and created a webserver script. That works fine, but it runs as root user.

I know that's not good (root-user & webserver = unsafe).

How can I run the webserver script as an non-root user? Does somebody know a good detailed tutorial or can give me some advice?

Upvotes: 1

Views: 892

Answers (2)

Nitzan Shaked
Nitzan Shaked

Reputation: 13598

You have two options:

Listen on port 80

Run as root, start your app's listen() on port 80 and them immediately drop to non-root. This is what Apache does, for example. Not recommended since it's easy to get this wrong, and lots of other details (writing to log files, initialization required before you can listen, etc.). Not standard practice in node.

Listen on port >=1024*

Run as non-root, listen on a port >= 1024 (say: 8000, or 8080), and have someone else listen on port 80 and relay port 80 traffic to you. That someone else can be:

  1. A load-balancer, NAT, proxy, etc. (Maybe an EC2 load balancer if you're running on EC2, e.g.)

  2. Another http server, say Apache httpd or ngnix.

For an ngnix example, see this: Node.js + Nginx - What now?

Upvotes: 2

Christos Papoulas
Christos Papoulas

Reputation: 2568

you can just run node hello.js

Upvotes: 0

Related Questions