【问题标题】:Compute Engine : "This site can’t be reached"Compute Engine:“无法访问此站点”
【发布时间】:2021-04-23 16:24:56
【问题描述】:

情况:

我正在关注this 教程。

当我到达创建实例并执行必要命令的部分时,我会看到以下内容:

To see the application running, go to http://[YOUR_INSTANCE_IP]:8080,

where [YOUR_INSTANCE_IP] is the external IP address of your instance.

问题:

页面无法加载。我收到以下错误消息:

This site can’t be reached

问题:

可能出了什么问题?

之前的所有步骤都运行良好,我可以在本地访问我的网站。

我通过检查等待 Compute Engine 实例准备就绪:

gcloud compute instances get-serial-port-output my-app-instance --zone us-central1-f 

虽然我将所有步骤重复了两次,但我仍然遇到错误消息。

一定少了点什么。


编辑:

我的防火墙规则:

【问题讨论】:

  • 你能在你的服务器上通过 SSH 验证服务是否在监听 8080 端口吗?即 netstat --listen 我还会检查您的服务器是否使用标签“http-server”。你可以运行“gcloud compute instances describe”
  • @Carlos 好像没有监听 8080 端口。netstat --listen 命令的输出中至少没有出现“8080”
  • 好的,至少我们知道服务已关闭。您在串行控制台中是否遇到任何错误?它是否显示启动脚本成功运行并安装了应用程序?
  • 这个命令“gcloud compute instances get-serial-port-output my-app-instance --zone us-central1-f”是否返回了教程中讨论的成功(即:“完成运行启动脚本”)?
  • @Coder1000 你能解决这个问题吗?如果是这样,请提供解决方案作为自我回答,这也将有助于社区遇到类似问题。

标签: node.js google-cloud-platform google-compute-engine


【解决方案1】:

我猜你没有将防火墙标签应用于实例?

首先,您可以检查您的计算实例标签。

gcloud compute instances describe my-app-instance

在您的示例中,您应该在标签项中看到 http-server,如下所示

tags:
  fingerprint: xxxxxxx
  items:
  - http-server
  - https-server

如果不存在,则应将标签添加到现有 VM 实例,使用此 gcloud 命令:

gcloud compute instances add-tags [YOUR_INSTANCE_NAME] --tags http-server,https-server

要在创建实例时添加标签,请在语句中包含该标志:

gcloud compute instances create [YOUR_INSTANCE_NAME] --tags http-server,https-server

【讨论】:

    【解决方案2】:

    如果您的代码和防火墙规则正确,那么您很可能尝试连接到错误的 IP。您应该使用外部 IP,而不是使用 ifconfig 获得的内部 IP,您可以通过 whatsmyip.com 获取外部 IP

    【讨论】:

      【解决方案3】:

      我会建议研究这一步:

      gcloud compute instances create my-app-instance \
      --image-family=debian-9 \
      --image-project=debian-cloud \
      --machine-type=g1-small \
      --scopes userinfo-email,cloud-platform \
      --metadata app-location=$BOOKSHELF_DEPLOY_LOCATION \
      --metadata-from-file startup-script=gce/startup-script.sh \
      --zone us-central1-f \
      --tags http-server
      

      请确保实例是使用 http-server 标签创建的

      否则防火墙规则不会对您的实例生效

      gcloud compute firewall-rules create default-allow-http-8080 \
      --allow tcp:8080 \
      --source-ranges 0.0.0.0/0 \
      --target-tags http-server \
      --description "Allow port 8080 access to http-server"
      

      【讨论】:

        【解决方案4】:

        首先,检查防火墙设置是否正确。

        第二,我遇到了同样的问题,并通过在“网络服务层”部分选择“标准”选项而不是“高级”选项来解决它。

        第三,使用命令检查同一个端口是否有其他应用在运行:

        netstat -tulpn

        应该返回如下内容:

        (Not all processes could be identified, non-owned process info
         will not be shown, you would have to be root to see it all.)
        Active Internet connections (only servers)
        Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
        tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -
        tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
        tcp6       0      0 :::80                   :::*                    LISTEN      -
        

        在我的情况下,它不起作用,因为我有两个应用程序在同一个端口上运行。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-04-09
          • 1970-01-01
          • 1970-01-01
          • 2017-12-07
          • 2017-03-29
          • 2021-02-09
          • 2021-09-22
          相关资源
          最近更新 更多