user967451
user967451

Reputation:

Not able to access a port on ec2 instance for an Angular app

I am working on an angular app using the angular cli to set things up. Running the ng serve command spawns a server at this address <my_ec2_host_name>:4200. When I try to access the page on the browser it doesn't work (connection timed out error). I believe this is because of security reasons so I added the following rule to my security groups for the ec2 instance:

enter image description here

Port 4200 should now be accessible but I still can't get the page to load. Can someone think of how to get this to work?

Upvotes: 1

Views: 3432

Answers (4)

Palla
Palla

Reputation: 1262

Start angular with below command.

ng serve --host=0.0.0.0 --disable-host-check

it will disable host check and allow to access with IP

Upvotes: 7

Prasanna Shiwakoti
Prasanna Shiwakoti

Reputation: 11

You can set up the host option like this:

ng serve -host 0.0.0.0

Upvotes: 1

Mason Bryant
Mason Bryant

Reputation: 1392

That looks correct. Are you sure that your server is running and listening for connections?

You should ssh to that server and verify that the page can be loaded locally. Eg:

curl http://<YOUR HOST IP ADDRESS>:4200
eg: curl http://54.164.10.123:4200

You should be careful to use the public ip address (eg: IPv4 Public IP when you're in the EC2 console). I've run into problems in the past where I've got a server listening on one IP address (often localhost) and not the public ip address.

Also maybe a problem: Is your host inside a VPC of some sort?

Upvotes: 0

Tom Paulus
Tom Paulus

Reputation: 135

The steps you are doing are correct for opening a port via Security Groups in the EC2 console. Make sure you are modifying the correct security group, and make sure that your changes have been saved.

Your container may have additional firewalls in place, so you will want to check the OS documentation. For Example, RHEL uses iptables as a further security measure: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security_Guide/sect-Security_Guide-IPTables.html.

Upvotes: 0

Related Questions