Only do this if you understand the consequences: all node programs will be able to bind on ports < 1024
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/node
Important: your node location may vary. Use which node
to find it, or use it directly in the command:
sudo setcap 'cap_net_bind_service=+ep' `which node`
In UNIX-like systems, non-root users are unable to bind to ports lower than 1024.
This is a nuisance when proxying adresses on port 80. Tipically, you end up sudo
ing all apps that must bind to such ports.
However, since kernel 2.6.24, you can use the setcap
command to set specific capabilities to a program.
To enable all node programs to bind on any port lower than 1024, issue the following command:
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/node
Voilà! You can now bind to port 80 without sudo
ing.
If your node
binary isn't on this path, find it with whereis node
and substitute /usr/local/bin/node
for wherever it is.
setcap
functions per-program. Therefore, if you update your node version you will probably need to run this command again.
@rodrigomuniz: this solution allows you to forward traffic from port 80 to port 8080, for example, on Mac OS X. Now you can bind to the upper port as if you were bound to the forwarded lower port. This is temporary and you would need to redo the mapping after each reboot. Maybe you might add step 2 to .bash_profile.
Step 1: View current firewall rules.
sudo ipfw show
Step 2: Add port forwarding rule (80 to 8080)
sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in
If you want to remove your firewall rules run:
sudo ipfw flush
[source]