NodeJs App in AWS using port 3000 is not accessibl

2020-05-07 19:47发布

问题:

I am using free tier AWS Linux instance, I had installed NodeJs and started my Express JS app (sudo node bin/www) my app is running on port 3000.

When I ssh to the instance and do cURL my app is responding but not from Chrome using Instance Public IP.

I have added Ports 80, 22, 3000 in Security Groups to access the app from anywhere. [Attached ScreenShot] The instance is running in N. Virginia region.

Following are the cases I tried to make it work:

  • Started my app using Public IP with port 3000
  • Started my app using Private IP with port 3000
  • Started my app using 0.0.0.0 with port 3000
  • Started my app using localhost with port 3000

All the above cases failed, when I ssh to the instance and do cURL my app is responding.

Could someone give me more insights on this? or I am missing anything. I have been blocked by this.

I am able to access app when I set the port to 80 but I need to use port 3000 because I am running Frontend Framework on port 80.

Softwares install on the server using yum:

  • yum update
  • gcc-c++ make
  • openssl-devel
  • nodejs from official website
  • npm install -g npm // update npm
  • mongodb

AWS Security Group Screenshot

P.S: I have read all the StackOverflow questions regarding the app not accessible from the internet, but in my case, my app is accessible from port 80 not from 3000.

回答1:

It could be that you are trying to reach your application from a network in which outbound connections on port 3000 are blocked. Most corporate network only allow some specific kinds of traffic to leave the network, usually http(s) and such. Try testing it from another network, or from an ec2-host within a different region.



回答2:

have you allowed CORS/origions?

var allowedOrigins = [origionDomain] 
res.header('Access-Control-Allow-Origin', allowedOrigins)