[英]Error accessing my webapp running inside my Azure vm using public IP
I know this is not the ideal way but nonetheless, I created an Azure VM and deployed my application running react.js as frontend, springboot as backend and database as mysql.我知道这不是理想的方法,但尽管如此,我创建了一个 Azure 虚拟机并将我的应用程序部署为运行 react.js 作为前端,springboot 作为后端,数据库作为 mysql。 I used already created docker images from dockerhub to run the containers.
我使用已经从 dockerhub 创建的 docker 映像来运行容器。 After running all the images as containers, if I user RDP to get a GUI for my VM, I can login and connect and all the components work fine.
在将所有图像作为容器运行后,如果我使用 RDP 为我的 VM 获取 GUI,我可以登录并连接,并且所有组件都可以正常工作。
But when I use public ip to open the homepage of my app, it is throwing me an error saying that it cannot connect to http://localhost:8081 which is my springboot url.但是当我使用 public ip 打开我的应用程序的主页时,它向我抛出一个错误,说它无法连接到http://localhost:8081这是我的 springboot Z572D4E421E5E6B9BC11D815EA8 Note that I am able to access my react-app running in my vm but not the springboot backend.
请注意,我可以访问在我的 vm 中运行的 react-app,但不能访问 springboot 后端。
Here are the snippets-以下是片段-
WebPage React-app running on Azure vm accessed using public ip在 Azure vm 上运行的WebPage React-app 使用公共 ip 访问
Error Error when react tries to access springboot for api calls react 尝试访问 springboot 以进行 api 调用时出错
Just to clarify here are all the port numbers I am using只是为了澄清这里是我正在使用的所有端口号
80- React app and also given as inbound port number in my virtual machine 8081- Springboot running in my vm 80- React 应用程序,并在我的虚拟机中作为入站端口号 8081- 在我的 vm 中运行的 Springboot
As react.js frontend will be running in the browser of users' side, the localhost
here is users side localhost, not your Azure VM's, so that users can't access your VM port.由于 react.js 前端会运行在用户端的浏览器中,这里的
localhost
是用户端的 localhost,而不是你的 Azure 的虚拟机,所以用户无法访问你的虚拟机端口。
In your react.js frontend code, you should specify your spring-boot URL as http://<your VM piblic IP>:8081
instead of localhost.在您的 react.js 前端代码中,您应该将 spring-boot URL 指定为
http://<your VM piblic IP>:8081
而不是And you need also to open the 8081 port in the Azure VM network security group so that this port could be accessed by the public network.并且还需要在Azure VM网络安全组中打开8081端口,使该端口可以被公网访问。 Detailes see this doc .
详情请参阅此文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.