URL 访问 google 云部署休息 API

URL to access google cloud deployed rest API

我开发了一个 rest api 并在 google 云 VM (GCE) 中进行了 docker 化和部署。 REST api 是端口 8080 上的 运行。我可以使用 curl http://0.0.0.0:8080/api/myapi 测试该应用程序。我还为实例配置了静态外部 IP 地址。但是我不确定如何通过互联网访问其余部分 api。

这里列出了您需要检查的事项,我将列出所有步骤供您检查和解决问题:

  1. 您需要有一个防火墙规则来允许来自 VM 端口的流量,这很重要,因为项目防火墙默认不打开端口 8080。

  2. VM 应具有外部 IP 地址和侦听所需端口的服务

  3. 容器必须有IP和端口开放

基本上,外人连接会是这样的:

浏览器:http://host-ip:8080 >> GCP 项目防火墙 >> 实例端口8080 >> 容器端口80 >> 连接成功!

意思是80是容器的端口,8080是在GCP中映射到主机VM上的端口。

故障排除步骤(该示例是使用 nginx 执行的,它默认打开端口 80/tcp 并映射到 VM 上的端口 8081):

  • Install Nmap

  • Check if the required ports are open on your container

  • Test through the container port and IP

  • Checked ports opened on your VM

  • Test through the VM port using instance internal IP

  • Test through the VM port using instance external IP

  • 使用实例外部 IP 使用浏览器进行测试(具体情况的格式应为 http://ext-ip:8080)

了解您的错误消息会很有用,但我建议您按照上述步骤验证使用的端口是否已在容器和 VM 实例中映射和打开。