3

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.

Rohith
  • 43
  • 2
  • 10
  • Your security groups look right, though it should also specify type on the group? Do you see type anywhere? Also could you post the code you use to start your node server. The issue could be there as well – Lucas Hendren Aug 11 '17 at 08:06
  • @Hammer Yes, I have set type to anywhere for port `3000` in `Security group`. Code to start app: `sudo node bin/www` – Rohith Aug 11 '17 at 08:12
  • Sorry let me clarify, i mean the actual code in the file you run that setups your server – Lucas Hendren Aug 11 '17 at 08:17
  • @Hammer, I am using `Express JS`, I have developed my app using `express generator` command: `npm install express-generator -g` There is standard `www` file to run the app, I just changed `var port = normalizePort('3000');` Please let me know if you need more information. – Rohith Aug 11 '17 at 08:23
  • have you allowed CORS/origions? var allowedOrigins = [config.allowedOrigins] res.header('Access-Control-Allow-Origin', allowedOrigins); – Lucas Hendren Aug 11 '17 at 17:34
  • I'm having the exact same issue. Same code works on any other machine (non aws). Seems to be a specific issue to aws. I'm blocked on this as well. – user2848810 Oct 08 '20 at 05:36

3 Answers3

3

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.

Andrei Socaciu
  • 1,198
  • 9
  • 20
  • Assume I have single AWS Instance, I have to run my Frontend Framework in `Port 80` and my Backend Framework in `Port 3000`, how I can solve this? How I can enable Users from Corporate Network also access my app without any break? – Rohith Aug 12 '17 at 10:38
  • 2
    @Rohith you'd probably need a reverse proxy. For example you'd run frontend say on port 4000 and backend on port 3000. On port 80 you setup a reverse proxy (apache or nginx) and configure it to forward requests to ports 3000 and 4000 depending on the url, for example all that starts with /api goes to backend, everything else goes to frontend. – Andrei Socaciu Aug 14 '17 at 08:02
  • Thanks for the information. Actually, I did the same. – Rohith Sep 29 '17 at 09:00
2

3 days wasted on this. You need to disable the internal firewall. I am on a centos 7:

sudo systemctl disable firewalld sudo systemctl stop firewalld

user2848810
  • 1,187
  • 1
  • 8
  • 12
0

have you allowed CORS/origions?

var allowedOrigins = [origionDomain] 
res.header('Access-Control-Allow-Origin', allowedOrigins)
Soviut
  • 88,194
  • 49
  • 192
  • 260
Lucas Hendren
  • 2,786
  • 2
  • 18
  • 33