3

i want to run my node.js application on port 80 without running it as root

$> which node
/usr/bin/node

I have tried to use setcap but it's not working:

$> sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/node
Failed to set capabilities on file `/usr/bin/node' (Operation not 
permitted)
The value of the capability argument is not permitted for a file. Or 
the file is not a regular (non-symlink) file

What am i doing wrong ?

  • 1
    Possible duplicate of [Best practices when running Node.js with port 80 (Ubuntu / Linode)](https://stackoverflow.com/questions/16573668/best-practices-when-running-node-js-with-port-80-ubuntu-linode) – Mornor Jun 11 '18 at 14:02

2 Answers2

4

Ports below 1000 require sudo privilege. You can use the following command to allow it to bind to port 80 without sudo:

sudo setcap 'cap_net_bind_service=+ep' `which node`
Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81
1

Finally, I have used port redirection, not with iptables but with ufw

https://serverfault.com/questions/238563/can-i-use-ufw-to-setup-a-port-forward