将 Nuxt JS SSR 应用程序部署到 Google Cloud App Engine Standard

时间:2021-07-14 21:08:40

标签: node.js google-app-engine google-cloud-platform nuxt.js

我无法将 Nuxt JS SSR 应用部署到 Google Cloud App Engine。 该应用可以在开发模式和生产模式下在本地运行。

Nuxt JS 文档建议使用 app.yaml 如下:

runtime: nodejs10

instance_class: F2

handlers:
  - url: /_nuxt
    static_dir: .nuxt/dist/client
    secure: always

  - url: /(.*\.(gif|png|jpg|ico|txt))$
    static_files: static/\1
    upload: static/.*\.(gif|png|jpg|ico|txt)$
    secure: always

  - url: /.*
    script: auto
    secure: always

env_variables:
  HOST: '0.0.0.0'

但是,Google Cloud 文档建议使用 nodejs14env_variables 作为存储桶名称,我认为该名称与 Google App Engine 自动创建的暂存存储桶名称相同。

runtime: nodejs14 # or another supported version

instance_class: F2

env_variables:
  BUCKET_NAME: "staging.myapp.appspot.com"

handlers:
  - url: /_nuxt
    static_dir: .nuxt/dist/client
    secure: always

  - url: /(.*\.(gif|png|jpg|ico|txt))$
    static_files: static/\1
    upload: static/.*\.(gif|png|jpg|ico|txt)$
    secure: always

  - url: /.*
    script: auto
    secure: always

当使用这两种 app.yaml 配置进行部署时,它会成功部署到 Google App Engine,但是在访问实例的 URL (myapp.uk.r.appspot.com) 时,我是遇到错误如下:

Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.

在访问 staging.myapp.appspot.com 时,我遇到了一系列错误,从一般的 Google 404 错误到证书错误。有没有人知道将 Nuxt JS SSR 应用部署到 Google Cloud App Engine 的正确 app.yaml 配置?

3 个答案:

答案 0 :(得分:2)

<块引用>

有人知道将 Nuxt JS SSR 应用部署到 Google Cloud App Engine 的正确 app.yaml 配置吗?

我复制了您的案例,并使用您提供的 app.yaml 配置在 App Engine 中部署了 Nuxt JS 应用程序的基本教程。即使我将 instance_classF2 减少到 F1,这两种配置都可以正常工作,它仍然运行良好。

截至目前,nodejs 的推荐版本为 nodejs14,但即使版本为 nodejs10,该应用仍可在 App Engine Standard 中运行。 env_variables 是可选的,您可以在 app.yaml 文件中定义环境变量以使其可用或在您的应用中使用。

错误:

Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.

500 errorserver error 很难找到原因。在 Cloud Logging 中查找日志或单击此 link 以直接转到控制台。确保您位于 GAE 应用程序 > 您的服务名称 > App Engine 版本。开始查找访问应用程序时出现的错误并查找错误原因描述。如果你没有找到任何尝试切换到所有日志。

请注意,它还需要已启用以下 API:

  1. App Engine API
  2. Compute Engine API
  3. Cloud Build API

其他故障排除,仔细检查应用程序上的侦听端口。

答案 1 :(得分:1)

请检查应用程序日志以确保 GAE 上发生了什么

gcloud app logs tail

然后也试试我的 yaml 文件用于 nuxt SSR:

runtime: nodejs14
service: nuxt

instance_class: F1

handlers:
  - url: /_nuxt
    static_dir: .nuxt/dist/client
    secure: always

  - url: /(.*\.(gif|png|jpg|ico|txt))$
    static_files: static/\1
    upload: static/.*\.(gif|png|jpg|ico|txt)$
    secure: always

  - url: /.*
    script: auto
    secure: always

答案 2 :(得分:0)

解决了在 nuxt.config.js 中指定不同的服务器端口 8000 而不是默认值似乎是一个疏忽的问题。

通过查看日志使用:

gcloud app logs tail

这个错误变得明显:

 ✖ Nuxt Fatal Error
Error: listen EADDRNOTAVAIL: address not available *.*.*.*:8000
相关问题