Reputation: 356
I'm trying to deploy a NodeJS/React app on an ec2 instance on AWS.
My app runs fine on port 3000, but is not being forwarded to port 80.
Neither modifying proxy_pass or modifying iptables seems to work in this scenario.
I've tried the following:
Modifying Nginx's server configuration to forward port 3000 to port 80. My Nginx configuration:
server {
listen 80;
location / {
proxy_pass http://[My Private ec2 IP]:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
server_name example.com www.example.com;
}
}
Modifying iptables to forward port 3000 to port 80.
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
My directory is structured as follows:
- appname/
- /api (node.js server-side code)
- /client (React client-side code)
I have tried running npm start
from within appname/client/
as well as npm build
. sudo netstat -lntp | grep 80
shows no processes listening on port 80, so the port is available.
The app renders on [public IP]:3000
. When I try to access [public IP]
, the browser displays 'This site can't be reached'.
This seems like a fairly straightforward thing to do, yet nginx and iptables configurations both are ignored. Am I missing something?
Upvotes: 1
Views: 2285
Reputation: 2982
Ports are also needed to forward from Amazon EC2 instance's console panel. In order to enable ports from EC2 instance console panel, perform the below mentioned steps:
Security groups
in bottom panelassigned security group
name, it should something like launch-wizard-{number}
inbound
tab from the bottom panelYou can check the below URL to get more info about Amazon EC2 Port Forwarding
https://aws.amazon.com/premiumsupport/knowledge-center/connect-http-https-ec2/
Upvotes: 1