I managed to get my Angular 5 app running on AWS EC2 Ubuntu...
Started standard Ubuntu instance, used PuTTy to shell in, installed node, entered the next 4 \"magic l
You need to check few things in your EC2 instance first
First check that port 4200 or any port that you want to use for Angular is added in security group to accept the traffic.
After allowing the port run ng serve with correct domain name or Public DNS shown in EC2 Instance for example
"ec2-xx-xx-xx-xx.eu-west-1.compute.amazonaws.com"
Hot Fix:
If you are getting this error with localhost:4200 you can try ng serve --host 0.0.0.0
To add specific port you can execute the command as follows: ng serve --host 0.0.0.0 --port 4200
Hope this will fix your issue.
Use
ng serve --port 4202 --host 0.0.0.0 --publicHost ec2-your-public-host-link.com
First of all, please note that the built-in webserver in ng-cli is not intended to be used in production. I strongly advise you to find a better solution if this is for production.
In order to access the site from other devices/ over the internet, you have to instruct ng-cli to serve it at the correct IP-adress. You can do that by running ng serve --host x.x.x.x
.
It will probably work if you enter your servers LAN-IP (depending on your setup). You can find it by running ifconfig
.
However, since you are hosting a static website, an alternative solution is to simply host the app on S3. To do that, run ng build --prod
and upload the dist-folder to AWS S3. They have a tutorial for that here.
Alternatively, you can use something like Apache or nginx to serve your compiled app from your EC2-instance.