Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start node.js on port 80 on a linux server?

When I try to start node on port 80, the error tells me that the port is in use. I imagine that's Apache.

What is the proper way to "take over" port 80, and keep it that way after a server restart?

(Linux xxxx.__.com 2.6.32-5-amd64 #1 SMP Tue Jun 14 09:42:28 UTC 2011 x86_64 GNU/Linux)

like image 228
dsp_099 Avatar asked Dec 09 '22 13:12

dsp_099


2 Answers

you can use ip tables to map port 80 to 8000

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000

to make it permanent

sudo sh -c "iptables-save > /etc/iptables.rules"

and add

pre-up iptables-restore < /etc/iptables.rules

to your /etc/network/interfaces

like image 77
supernova Avatar answered Dec 11 '22 03:12

supernova


To take over port 80 when another process is listening on it, you must kill the process (or somehow tell it to stop listening). To ensure that Apache doesn't try to listen on port 80 again the next time it starts, you need to edit its configuration or prevent it from starting up.

To see which process is listening on port 80, run sudo netstat -ntap and look for the row with Local Address ending in port :80. The PID of the process (and the name) is in the far right column.

like image 25
sqs Avatar answered Dec 11 '22 02:12

sqs