如何从 Google 云虚拟机部署 Hugo 网站?
How to deploy a Hugo website from a Google Cloud VM?
我已经启动了一个 Google 云虚拟机,其外部 IP 地址为 35.225.45.169:
只是为了检查我是否可以从那里为网站提供服务,我克隆了一个 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
我是不是漏掉了什么?我应该如何将此静态网站从 Google 云计算实例部署到互联网?
更新
根据 Ahmet 的评论,我编辑了 VM 以允许 HTTP 和 HTTPS 流量。这似乎在 VPC 网络选项卡中创建了多个防火墙规则(见下文)。
但是,此后我仍然无法访问 http://35.225.45.169:1313/;是否有我必须定义的特定规则?
您必须创建允许 tcp:1313
端口的新防火墙规则。
但是为什么要在 GCP VM 上托管 Hugo 网站?
您检查过在 GCS 上托管 Hugo 网站还是使用 Firebase?
https://gohugo.io/hosting-and-deployment/hosting-on-firebase/
How to deploy a Hugo website from a Google Cloud VM?
如 pradeep 所述,您需要创建一个新的防火墙规则,允许端口 tcp:1313
接收和传出流量。
Here 您将在 Google Cloud Platform 中找到有关如何创建防火墙规则的更多详细信息。
尽管如此,我认为有更好的方法取决于您想要服务的网站。 Here 您会在 Google Cloud Platform 中找到可用于服务网站的不同选项,但主要有以下三种:
- 使用 Google 云存储。
- 使用 Google App Engine。
- Firebase 托管。
Google 云存储
如果您提供的是静态网站,我强烈建议您使用 Google 云存储或 Firebase 托管。的确,它们既没有负载平衡功能也没有日志记录功能,但如果您是 Google Cloud Platform 的新手,它们是一种简单的方法。
如图here if you would like to host a static site, you could do it within Cloud Storage, but you will need to create a Cloud Storage Bucket,将内容上传到里面
Here 您将找到有关如何使用 Google 云存储在 Google 云平台中托管静态网站的更多信息和教程。
Google 应用引擎
另一种选择是使用 App Engine,它不仅由 Google 的基础架构完全管理,而且比启动 VM 并确保 X 端口打开或不,Google 为你做。
我附上了有关如何托管 Hugo on Google App Engine 的教程。
Firebase 托管
最后,您还可以使用 Firebase 托管 来为您的 Hugo 网站提供服务。我附上了一些关于 Firebase 托管的更多详细信息的文档 here。
希望对您有所帮助。
我已经启动了一个 Google 云虚拟机,其外部 IP 地址为 35.225.45.169:
只是为了检查我是否可以从那里为网站提供服务,我克隆了一个 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
我是不是漏掉了什么?我应该如何将此静态网站从 Google 云计算实例部署到互联网?
更新
根据 Ahmet 的评论,我编辑了 VM 以允许 HTTP 和 HTTPS 流量。这似乎在 VPC 网络选项卡中创建了多个防火墙规则(见下文)。
但是,此后我仍然无法访问 http://35.225.45.169:1313/;是否有我必须定义的特定规则?
您必须创建允许 tcp:1313
端口的新防火墙规则。
但是为什么要在 GCP VM 上托管 Hugo 网站? 您检查过在 GCS 上托管 Hugo 网站还是使用 Firebase? https://gohugo.io/hosting-and-deployment/hosting-on-firebase/
How to deploy a Hugo website from a Google Cloud VM?
如 pradeep 所述,您需要创建一个新的防火墙规则,允许端口 tcp:1313
接收和传出流量。
Here 您将在 Google Cloud Platform 中找到有关如何创建防火墙规则的更多详细信息。
尽管如此,我认为有更好的方法取决于您想要服务的网站。 Here 您会在 Google Cloud Platform 中找到可用于服务网站的不同选项,但主要有以下三种:
- 使用 Google 云存储。
- 使用 Google App Engine。
- Firebase 托管。
Google 云存储
如果您提供的是静态网站,我强烈建议您使用 Google 云存储或 Firebase 托管。的确,它们既没有负载平衡功能也没有日志记录功能,但如果您是 Google Cloud Platform 的新手,它们是一种简单的方法。
如图here if you would like to host a static site, you could do it within Cloud Storage, but you will need to create a Cloud Storage Bucket,将内容上传到里面
Here 您将找到有关如何使用 Google 云存储在 Google 云平台中托管静态网站的更多信息和教程。
Google 应用引擎
另一种选择是使用 App Engine,它不仅由 Google 的基础架构完全管理,而且比启动 VM 并确保 X 端口打开或不,Google 为你做。
我附上了有关如何托管 Hugo on Google App Engine 的教程。
Firebase 托管
最后,您还可以使用 Firebase 托管 来为您的 Hugo 网站提供服务。我附上了一些关于 Firebase 托管的更多详细信息的文档 here。
希望对您有所帮助。