Reputation: 13
I am trying to get a NodeJs application to run on a Amazon Linux server using port 80. Currently when I run the app it is defaulting to port 1024. I understand that this is due to the fact that I have to be root to run on port 80 but given I am on a aws linux box I am not able to run that as root. I have been digging for awhile but I am coming up short on what I need to adjust to get this to run properly.
Upvotes: 0
Views: 2715
Reputation: 459
Here's an ACTUAL answer.
Use iptables to forward traffic to whichever port you want to use. You'll have to use sudo to set this initially but otherwise you can run your web server without superuser privileges.
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000
BONUS
To set up HTTPS without a load balancer you can use Let's Encrypt. To do that, install certbot following these instructions. You'll have to open port 443 and serve your website on that port too.
You can read more about your case with Node.js here.
Sources:
Upvotes: 0
Reputation: 14905
sudo bash
will allow you to connect as root
on your EC2 Amazon Linux instance.
I would question why
do you want to run NodeJS on port 80, the best practice would have a load balancer in front of your instance to accept HTTPS calls and relay to whatever port nodejs will run on your instance, in a private subnet.
I would suggest to read this doc to learn how to do this : https://aws.amazon.com/getting-started/projects/deploy-nodejs-web-app/
Upvotes: 0