简体   繁体   English

访问谷歌云部署的休息 API 的 URL

[英]URL to access google cloud deployed rest API

I have developed a rest api and dockerized and deployed in google cloud VM (GCE).我已经开发了一个 rest api 并在 google cloud VM (GCE) 中进行了dockerized 和部署。 the REST api is running on port 8080. I am able to test the app using curl http://0.0.0.0:8080/api/myapi . REST api 在端口 8080 上运行。我能够使用 curl http://0.0.0.0:8080/api/myapi测试应用程序。 I have also configured static external IP address for the instance.我还为实例配置了静态外部 IP 地址。 However I am not sure how I can access this rest api over internet.但是我不确定如何通过互联网访问这个休息 api。

There's a list of things that you would need to check on this, I'll list all the steps for you to check and troubleshoot:有一个您需要检查的事项列表,我将列出您检查和排除故障的所有步骤:

  1. You need to have a Firewall rule to allow traffic from the VM port, this is important because port 8080 is not open by default on the project Firewall.您需要有一个防火墙规则来允许来自 VM 端口的流量,这很重要,因为默认情况下,项目防火墙上的端口 8080 未打开。

  2. The VM should have an external IP address and a service listening on the desired port VM 应具有外部 IP 地址和侦听所需端口的服务

  3. The container must have an IP and port open容器必须有一个 IP 和端口打开

Basically, outsider connections will go like this:基本上,外部连接会像这样:

Browser:http://host-ip:8080 >> GCP project firewall >> Instance port 8080 >> container port 80 >> succesfull connection!浏览器:http://host-ip:8080 >> GCP 项目防火墙>>实例端口 8080 >>容器端口 80 >>成功连接!

Meaning that 80 is the container's port and 8080 is the port mapped on the host VM in GCP.这意味着 80 是容器的端口,8080 是映射到 GCP 中主机 VM 的端口。

Troubleshooting Steps (The example was performed with nginx which by default has the port 80/tcp open and was mapped to the port 8081 on the VM):故障排除步骤(该示例是使用 nginx 执行的,默认情况下,它打开了端口 80/tcp 并映射到 VM 上的端口 8081):

It will be useful to know your error message, but I suggest you to follow the above steps to validate if used ports are mapped and opened in the container and in the VM instance.了解您的错误消息会很有用,但我建议您按照上述步骤验证使用的端口是否已在容器和 VM 实例中映射和打开。

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

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