How do I run Node.js on port 80? How do I run Node.js on port 80? apache apache

How do I run Node.js on port 80?


run your app on a high port 8080 or whatev then

sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

If you are not using ngnix or apache


The simplest solution: safely configure your node app to run on port 80.

  • sudo apt-get install libcap2-bin
  • sudo setcap cap_net_bind_service=+ep /path/to/node
  • Ta da! You're done.

Why do I like it?

  • You don't have to use apache or nginx
  • You don't have to run your application as root
  • You won't have to forward ports (and handle that each time your machine boots)

Reference Link: https://www.digitalocean.com/community/tutorials/how-to-use-pm2-to-setup-a-node-js-production-environment-on-an-ubuntu-vps (A great article on how to set up your node app on cloud hosting).


What you need to do is have 2 ip's for the server you are running. Apache has 1 ip bound to port 80 and then node.js has the other ip bound to port 80.

Using node and its listen directive has 2 values eg. .listen(80, NODEJS_IP or DNS NAME);

Some other advice.

I would not use apache with nodejs as it's not evented. So this really isn't recommended. I would actually look into using NGINX as its a much better pairing with Node.