代码之家  ›  专栏  ›  技术社区  ›  tomrcht

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

  •  10
  • tomrcht  · 技术社区  · 7 年前

    我很难找到如何将多个域映射到GAE中的多个服务。以下是配置:

    • 一个应用程序是Go API,部署在标准环境中的GAE中
    • 第二个应用程序是角度应用程序,也部署在标准环境中的GAE中,但作为另一个服务。

    以下是应用程序。yaml文件:

    Go应用程序。亚马尔

    runtime: go
    api_version: go1.9
    
    handlers:
    - url: /.*
      script: _go_app
    

    角度应用程序。亚马尔

    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。领域com公司 角度应用程序 领域com公司 .

    通过转到 App引擎(>);设置(>);自定义域 我成功地为我的API添加了域,它工作得很好。
    但现在,我找不到绘制地图的方法 领域com公司 我的角度应用。使用相同的设置并不能让我选择将不同的服务映射到我的域。

    谢谢你的帮助,祝你今天愉快!

    2 回复  |  直到 7 年前
        1
  •  28
  •   Inzamam Malik    4 年前

    要映射子域,可以使用 dispatch.yaml 文件例如:

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

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

    一旦你有了榜样。在App Engine下添加com>设置(>);自定义域对于默认服务,可以添加子域api。实例其他服务的com。稍后,您需要向您的域注册器添加新的子域DNS记录,如控制台配置中所述。

        2
  •  1
  •   Dan Cornilescu    7 年前

    你想先映射你的裸体 domain.com 到你的应用程序。

    然后选择添加另一个域,您可以选择添加 api (或任何其他) 领域com公司 特定服务的子域。

    请注意,这两个服务中存在冲突/重叠的处理程序模式: - url: /.* ,这将不起作用,因为GAE不知道将这些请求定向到哪个服务,它们最终都将发送到同一个服务。您需要以不重叠的方式对请求URL名称空间进行分区,并且可能需要 dispatch.yaml 文件。看见 Mapping subdomain to a service in Google App Engine project 详细信息。