如何在Google App Engine中为每个服务绑定一个域/子域?

tom*_*cht 4 google-app-engine google-cloud-platform

我发现在GAE中如何将多个域映射到多个服务时遇到很多麻烦。这是配置:

  • Go API是一个应用程序,已在标准环境中部署在GAE中
  • 第二个应用程序是Angular应用程序,它也在标准环境中作为另一项服务部署在GAE中。

这是app.yaml文件:

转到应用程序app.yaml

runtime: go
api_version: go1.9

handlers:
- url: /.*
  script: _go_app
Run Code Online (Sandbox Code Playgroud)

Angular应用程序app.yaml

service: stage
runtime: python27
api_version: 1
threadsafe: true

skip_files:
- ^(?!dist)  # Skip any files not in the dist folder

handlers:
# Routing for bundles to serve directly
- url: /((?:inline|main|polyfills|styles|vendor)\.[a-z0-9]+\.bundle\.js)
  secure: always
  redirect_http_response_code: 301
  static_files: dist/\1
  upload: dist/.*

# Routing for a prod styles.bundle.css to serve directly
- url: /(styles\.[a-z0-9]+\.bundle\.css)
  secure: always
  redirect_http_response_code: 301
  static_files: dist/\1
  upload: dist/.*

# Routing for typedoc, assets and favicon.ico to serve directly
- url: /((?:assets|docs)/.*|favicon\.ico)
  secure: always
  redirect_http_response_code: 301
  static_files: dist/\1
  upload: dist/.*

# Any other requests are routed to index.html for angular to handle so we don't need hash URLs
- url: /.*
  secure: always
  redirect_http_response_code: 301
  static_files: dist/index.html
  upload: dist/index\.html
  http_headers:
      Strict-Transport-Security: max-age=31536000; includeSubDomains
      X-Frame-Options: DENY
Run Code Online (Sandbox Code Playgroud)

我有一个域,想将Go API绑定到api.domain.com,并将Angular应用绑定到domain.com

通过转到App Engine>设置>自定义域,我设法为我的API添加了域,并且该域运行正常。
但是现在,我找不到将domain.com映射到我的Angular应用程序的方法。进行相同的设置不会给我提供将其他服务映射到我的域的选项。

感谢您的帮助,祝您有美好的一天!

Fed*_*zio 7

要映射子域,您可以使用dispatch.yaml文件。一个例子:

dispatch:
    - url: "example.com/*"
    service: default

  - url: "api.example.com/*"
    service: otherservice
Run Code Online (Sandbox Code Playgroud)

然后运行$ gcloud app deploy dispatch.yaml(可以在任何目录中)。

在为默认服务在App Engine>设置>自定义域下添加example.com之后,您可以为其他服务添加子域api.example.com。稍后,您需要按照控制台配置中的说明,将新的子域DNS记录添加到域注册商中。