我在查找如何将多个域映射到 GAE 中的多个服务时遇到了很多麻烦。这是配置:
- 一个应用程序是 Go API,部署在标准环境中的 GAE 中
- 第二个应用程序是 Angular 应用程序,也部署在标准环境中的 GAE 中,但作为另一个服务。
以下是 app.yaml 文件:
Go application app.yaml
runtime: go
api_version: go1.9
handlers:
- url: /.*
script: _go_app
Angular application 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。
通过转到App Engine> 设置>自定义域,我设法为我的 API 添加了域,它运行良好。
但是现在,我找不到将domain.com映射到我的 Angular 应用程序的方法。转到相同的设置不会为我提供将其他服务映射到我的域的选项。
感谢您的帮助,祝你有美好的一天!
要映射子域,您可以使用 dispatch.yaml 文件。举个例子:
dispatch:
- url: "example.com/*"
service: default
- url: "api.example.com/*"
service: otherservice
然后运行$ gcloud app deploy dispatch.yaml
(它可以在任何目录中(。
在默认服务的 App Engine>设置>自定义域下添加 example.com 后,您可以为其他服务添加子域 api.example.com。稍后,您需要将新的子域 DNS 记录添加到域注册机构,如控制台配置中所述。
你希望首先将裸domain.com
映射到应用。
然后选择添加另一个域,您可以选择将api
(或任何其他(domain.com
子域添加到特定服务。
请注意,您在 2 个服务中存在冲突/重叠的处理程序模式:- url: /.*
,这将不起作用,因为 GAE 不知道将此类请求定向到哪个服务,它们最终都会发送到同一个服务。您需要以非重叠的方式对请求 URL 命名空间进行分区,并且可能还需要一个dispatch.yaml
文件。有关详细信息,请参阅将子域映射到 Google App Engine 项目中的服务。