AWS EC2 Angular 5 ng服务无法通过浏览器连接 [英] AWS EC2 Angular 5 ng serve not connecting via browser

查看:211
本文介绍了AWS EC2 Angular 5 ng服务无法通过浏览器连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法使Angular 5应用程序在AWS EC2 Ubuntu上运行...

I managed to get my Angular 5 app running on AWS EC2 Ubuntu...

启动了标准Ubuntu实例,使用PuTTy进行了安装,安装了节点,并输入了接下来的4条魔术线 ...

Started standard Ubuntu instance, used PuTTy to shell in, installed node, entered the next 4 "magic lines"...

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile

设置了我的公司目录,为@ angular / cli安装了全局npm,克隆了我的git,将目录更改为项目子文件夹,为@ angular / cli安装了本地npm,并然后为我的项目运行npm install。此时,在上述任何一个步骤中,我都可以运行ng服务,而不会出现严重错误!

made my company dir, did a global npm install for @angular/cli, cloned my git, changed dir to project subfolder, did a local npm install for @angular/cli, and then ran npm install for my project. At this point, I was able to run ng serve with no serious errors during any of the above steps! whew!

它表明它愉快地在端口4200上运行。我什至用netstat -anp检查了一下! grep 4200以及telnet 127.0.0.14200。是的,一切正常。

It showed it was happily running on port 4200. I even checked with netstat -anp | grep 4200 and also with telnet 127.0.0.1 4200. Yep all working.

然后,我进入AWS仪表板,并为我的实例创建了一个安全组,打开HTTP和具有默认值的HTTPS,然后为打开到任何位置的端口范围4200添加一个自定义TCP规则,并保存。但是,当我进入浏览器并输入 http://xx.xx.xx.xx:4200 (其中x是AWS分配给我的实例的公共IP),我收到无法建立与服务器的连接错误。

Then I went into the AWS dashboard, and created a security group for my instance, turning on HTTP and HTTPS with default values, and then adding one custom TCP rule for Port Range 4200 open to Anywhere, and saved. However, when I go to a browser and enter http://xx.xx.xx.xx:4200 (where the x's are the public IP that AWS assigned to my instance), I get a "can’t establish a connection to the server" error.

我缺少什么?

推荐答案

首先,请注意ng-cli中的内置Web服务器是不打算用于生产。我强烈建议您为生产解决方案找到更好的解决方案。

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.

为了从其他设备/通过互联网访问该网站,您必须指示ng-cli以正确的IP地址提供它。您可以通过运行 ng serve --host xxxx 来做到这一点。

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.

如果您输入服务器,它可能会工作LAN-IP(取决于您的设置)。您可以通过运行 ifconfig 来找到它。

It will probably work if you enter your servers LAN-IP (depending on your setup). You can find it by running ifconfig.

但是,由于您托管的是静态网站,因此,另一种解决方案是只需将应用托管在S3上。为此,请运行 ng build --prod 并将dist文件夹上传到AWS S3。他们在此处 a>。

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.

或者,您可以使用Apache或nginx之类的东西从EC2-instance服务已编译的应用程序。

Alternatively, you can use something like Apache or nginx to serve your compiled app from your EC2-instance.

这篇关于AWS EC2 Angular 5 ng服务无法通过浏览器连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆