简体   繁体   中英

AWS localhost with whatever port

I have an EC2 instance thats running an apache server that I can access just fine. However I also have three api's that I am running on that same EC2 instance. 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. 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. Without having to use an additional service such as AWS api gateway, why might it have an issue connecting?

I think your problem arises from the fact that you are calling localhost instead of your EC2 IP/domain name.

When you call localhost , that means whatever computer you are at. For backend, localhost is encouraged since you are on the same computer. But on the frontend, your website tries to go to localhost:3007 , which is the client computer. You need to change it to either ec2-<<your EC2 public IP here>>.compute-1.amazonaws.com or your EC2 Public IP.

You can find these here:

EC2 DNS区域

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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