简体   繁体   English

使用公共 IP 访问在我的 Azure vm 中运行的 webapp 时出错

[英]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 访问

在 Azure vm 上运行的 React-app 使用公共 ip 访问

Error Error when react tries to access springboot for api calls react 尝试访问 springboot 以进行 api 调用时出错

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.

相关问题 Node.js 应用程序不会在我的公共 IP 上启动 - Node.js application wont start on my public IP 我应该使用什么来托管一个公共 JSON 文件,该文件很少在不重新部署我的整个 web 应用程序的情况下更改? - What should I use to host a public JSON file that rarely changes without redeploying my whole webapp? React 前端连接到我计算机上的开发服务器,而不是 Azure VM 上的节点服务器,它托管在为什么使用 localhost - React front end connects to the development server on my computer instead of the Node server on Azure VM where it is hosted from why using localhost 使用Webpack后如何在静态服务器上提供我的React Webapp? - How to serve my React webapp on static server after using Webpack? 通过Azure WebApp在本地运行React应用 - Running React app through Azure WebApp locally ReactJS 在我的 azure 租户内注册 - ReactJS registering inside my azure tenant 为我的反应 web 应用程序访问 Azure SQL 数据库 - Accessing Azure SQL database for my react web application 使用axios发布请求访问我的API中的数据 - Accessing data inside my API with axios post request 直接访问 URL(在我的例子中是本地主机)时,如何在不使用按钮的情况下弹出登录屏幕(Azure AD)? - How to popup login screen(Azure AD) without using a button when accessing URL(local host in my case) directly? 我的反应应用程序没有运行并出现错误 - My react application is not running and getting error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM