Skip to content

Instantly share code, notes, and snippets.

View akshaym-hotstar's full-sized avatar

Akshay Mahajan akshaym-hotstar

View GitHub Profile
@krazylearner
krazylearner / node-port-forwarding.txt
Created March 27, 2016 20:20
redirect port 80 to port 3000 or any other in nodejs environment on ubuntu
What I do on my cloud instances is I redirect port 80 to port 3000 with this command:
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
Then I launch my Node.js on port 3000. Requests to port 80 will get mapped to port 3000.
You should also edit your /etc/rc.local file and add that line minus the sudo. That will add the redirect when the machine boots up. You don't need sudo in /etc/rc.local because the commands there are run as root when the system boots.
Logs
Use the forever module to launch your Node.js with. It will make sure that it restarts if it ever crashes and it will redirect console logs to a file.