如何在Google App Engine中为每个服务绑定一个域/子域? [英] How to bind one domain/subdomain per service in the Google App Engine?

查看:133
本文介绍了如何在Google App Engine中为每个服务绑定一个域/子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在查找如何将多个域映射到GAE中的多个服务时遇到很多麻烦.这是配置:

I have a lot of trouble finding how to map multiple domains to multiple services in the GAE. Here is the configuration :

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

这是app.yaml文件:

Here are the app.yaml files :

转到应用程序app.yaml

runtime: go
api_version: go1.9

handlers:
- url: /.*
  script: _go_app

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

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

I have a domain and want to bind the Go API to api.domain.com and the Angular app to domain.com.

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

By going to App Engine > Settings > Custom Domains I managed to add the domain for my API and it is perfectly working.
But now, I cannot find a way to map domain.com to my Angular application. Going to the same settings does not gives me an option to map a different service to my domain.

感谢您的帮助,祝您愉快!

Thanks for the help and have a nice day !

推荐答案

要映射子域,您可以使用

To map subdomains you can use a dispatch.yaml file. An example:

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

  - url: "api.example.com/*"
    service: otherservice

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

And then run $ gcloud app deploy dispatch.yaml (it can be in any directory).

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

Once you have example.com added under App Engine > Settings > Custom Domains for the default service, you can add the subdomain api.example.com for the other service. Later you need to add the new subdomain DNS records to you domain registrar as pointed out in the console configuration.

这篇关于如何在Google App Engine中为每个服务绑定一个域/子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆