AWS EC2 Angular 5 ng serve not connecting via browser

后端 未结 3 1017
花落未央
花落未央 2021-01-14 06:04

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

相关标签:
3条回答
  • 2021-01-14 06:33

    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.

    0 讨论(0)
  • 2021-01-14 06:41

    Use

    ng serve  --port 4202 --host 0.0.0.0 --publicHost ec2-your-public-host-link.com
    
    0 讨论(0)
  • 2021-01-14 06:43

    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.

    0 讨论(0)
提交回复
热议问题