如何从 Google Cloud VM 部署 Hugo 网站?

我已经启动了一个外部 IP 地址为 35.225.45.169 的 Google Cloud VM:

http://img3.mukewang.com/6267dca40001da1a15970253.jpg

只是为了检查我是否可以从那里为网站提供服务,我克隆了一个 Hugo 启动的项目并运行hugo server --bind=0.0.0.0 --baseURL=http://0.0.0.0:1313:


kurt_peek@mdm:~/synamdm$ hugo server --bind=0.0.0.0 --baseURL=http://0.0.0.0:1313

Building sites … WARN 2020/01/02 04:36:44 .File.Dir on zero object. Wrap it in if or with: {{ with .File }}{{ .Dir }

}{{ end }}

                   | EN  

+------------------+----+

  Pages            | 16  

  Paginator pages  |  0  

  Non-page files   |  0  

  Static files     | 20  

  Processed images |  0  

  Aliases          |  0  

  Sitemaps         |  1  

  Cleaned          |  0  

Built in 112 ms

Watching for changes in /home/kurt_peek/synamdm/{content,layouts,static,themes}

Watching for config changes in /home/kurt_peek/synamdm/config.toml

Environment: "development"

Serving pages from memory

Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender

Web Server is available at http://0.0.0.0:1313/ (bind address 0.0.0.0)

Press Ctrl+C to stop

现在我希望能够在我的浏览器中访问http://35.225.45.169:1313/并且该网站是可见的,但我发现它不是;而是操作超时(如下所示的curl命令):


> curl http://35.225.45.169:1313

curl: (7) Failed to connect to 35.225.45.169 port 1313: Operation timed out

我在这里错过了什么吗?我应该如何将这个静态网站从谷歌云计算实例部署到互联网?


狐的传说
浏览 182回答 2
2回答

慕桂英4014372

您必须创建一个允许tcp:1313端口的新防火墙规则。但是为什么要在 GCP 虚拟机上托管 Hugo 网站呢?您是否检查过在 GCS 上托管 Hugo 网站或使用 Firebase? https://gohugo.io/hosting-and-deployment/hosting-on-firebase/

PIPIONE

如何从 Google Cloud VM 部署 Hugo 网站?正如 pradeep 所提到的,您将需要创建一个新的防火墙规则,以允许端口tcp:1313接收和输出流量。在这里,您将找到有关如何在 Google Cloud Platform 中创建防火墙规则的更多详细信息。尽管如此,我认为根据您想要服务的网站,有更好的方法。在这里,您将找到可用于在 Google Cloud Platform 中为网站提供服务的不同选项,但主要有以下三种:使用谷歌云存储。使用谷歌应用引擎。Firebase 托管。谷歌云存储如果您正在为静态网站提供服务,我强烈建议您使用 Google Cloud Storage 或 Firebase Hosting。确实,它们没有负载平衡功能或日志记录,但如果您是 Google Cloud Platform 的新手,它们是一种简单的方法。如此处所示,如果您想托管一个静态站点,您可以在 Cloud Storage 中进行,但您需要创建一个Cloud Storage Bucket并将内容上传到其中。在这里,您将找到有关如何使用 Google Cloud Storage 在 Google Cloud Platform 中托管静态网站的更多信息和教程。谷歌应用引擎另一种选择是使用App Engine,它不仅完全由 Google 的基础架构管理,而且比启动 VM 并确保 X 端口是否打开更简单,Google 会为您完成。我附上了一份关于如何在 Google App Engine 上托管 Hugo的教程。Firebase 托管最后,您还可以使用Firebase 托管来为您的 Hugo 网站提供服务。我在此处附加了一些有关 Firebase 托管的详细信息的文档。我希望它有所帮助。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go