简体   繁体   English

任何端口的AWS localhost

[英]AWS localhost with whatever port

I have an EC2 instance thats running an apache server that I can access just fine. 我有一个运行apache服务器的EC2实例,我可以访问它。 However I also have three api's that I am running on that same EC2 instance. 但是我也有三个api,我在同一个EC2实例上运行。 these run on ports such as 3007 and I've allowed access to that port and my front end try to use localhost with those associated ports. 这些在3007等端口上运行,我允许访问该端口,我的前端尝试将localhost与这些相关端口一起使用。 Now when I start those API's they connect fine to my external resources such as a database however my front end can't connect to them. 现在,当我启动这些API时,它们可以很好地连接到我的外部资源,例如数据库,但是我的前端无法连接到它们。 Without having to use an additional service such as AWS api gateway, why might it have an issue connecting? 无需使用AWS api网关等附加服务,为什么连接时会出现问题?

I think your problem arises from the fact that you are calling localhost instead of your EC2 IP/domain name. 我认为您的问题源于您正在调用localhost而不是您的EC2 IP /域名。

When you call localhost , that means whatever computer you are at. 当你调用localhost ,这意味着你所在的计算机。 For backend, localhost is encouraged since you are on the same computer. 对于后端,因为您在同一台计算机上,所以鼓励使用localhost But on the frontend, your website tries to go to localhost:3007 , which is the client computer. 但是在前端,您的网站尝试转到localhost:3007 ,这是客户端计算机。 You need to change it to either ec2-<<your EC2 public IP here>>.compute-1.amazonaws.com or your EC2 Public IP. 您需要将其更改为ec2-<<your EC2 public IP here>>.compute-1.amazonaws.com或您的EC2公共IP。

You can find these here: 你可以在这里找到这些:

EC2 DNS区域

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM