本主題將討論虛擬主機設定。Apigee Hybrid 可透過虛擬主機處理多個網域名稱的 API 要求,並將 Proxy 基礎路徑路由至特定環境。
如要指定應將哪些環境專屬 API Proxy 基礎路徑導向至,請使用 virtualhosts.routingRules[] 設定屬性。如要進一步瞭解個別屬性,請參閱「設定屬性參考資料」中的「virtualhosts」。例如:
...
virtualhosts:
- name: vhost-one
hostAliases: ["api.example.com"]
sslCertPath: ./certs/fullchain.pem
sslKeyPath: ./certs/privkey.pem
routingRules:
- paths:
- /orders
- /items
env: test1
- paths:
- /customers
env: test2
envs:
- name: test1
serviceAccountPaths:
synchronizer: ./sa/synchronizer.json
udca: ./sa/udca.json
- name: test2
serviceAccountPaths:
synchronizer: ./sa/synchronizer.json
udca: ./sa/udca.json
當 API 呼叫 (例如:https://api.example.com/orders) 傳入時,要求會傳送至 test1 環境的訊息處理器。同樣地,如果收到對 https://api.example.com/customers 的要求,系統會將要求轉送至 test2 環境。
新增環境
如要新增環境,請將其設定新增至 envs[] 屬性,並新增 virtualhosts.routingRules.path 項目,指定要對應至新環境的基本路徑。在下列範例中,系統會新增名為 test3 的新環境,並更新 routingRules,將兩個路徑導向新環境:
virtualhosts:
- name: vhost-one
hostAliases: ["api.example.com"]
sslCertPath: ./certs/fullchain.pem
sslKeyPath: ./certs/privkey.pem
routingRules:
- paths:
- /orders
- /items
env: test1
- paths:
- /v0/hello
- /httpbin
env: test2
- paths:
- /v0/inventory
- /v0/customers
env: test3
envs:
- name: test1
serviceAccountPaths:
synchronizer: ./sa/synchronizer.json
udca: ./sa/udca.json
- name: test2
serviceAccountPaths:
synchronizer: ./sa/synchronizer.json
udca: ./sa/udca.json
- name: test3
serviceAccountPaths:
synchronizer: ./sa/synchronizer.json
udca: ./sa/udca.json
如要套用更新,您只需要套用 runtime 元件,如下所示:
apigeectl apply -f overrides-file.yaml -c runtime
新增多個虛擬主機
virtualhosts[] 屬性是陣列,因此您可以建立多個。每個虛擬主機都必須包含一組不重複的主機別名,也就是說,兩個虛擬主機不能共用相同的主機別名。舉例來說,新的虛擬主機 dev 會處理傳送至 api.internal.com 網域的流量。
virtualhosts:
- name: vhost-one
hostAliases: ["api.example.com"]
sslCertPath: ./certs/fullchain.pem
sslKeyPath: ./certs/privkey.pem
routingRules:
- paths:
- /orders
- /items
env: test1
- paths:
- /v0/hello
- /httpbin
env: test2
- paths:
- /v0/inventory
- /v0/customers
env: test3
- name: vhost-two
hostAliases: ["api.internal.com"]
sslCertPath: ./certs/fullchain.pem
sslKeyPath: ./certs/privkey.pem
routingRules:
- paths:
- /orders
- /items
env: test1
- paths:
- /v0/hello
- /httpbin
env: test2
- paths:
- /v0/inventory
- /v0/customers
env: test3
envs:
- name: test1
serviceAccountPaths:
synchronizer: ./sa/synchronizer.json
udca: ./sa/udca.json
- name: test2
serviceAccountPaths:
synchronizer: ./sa/synchronizer.json
udca: ./sa/udca.json
- name: test3
serviceAccountPaths:
synchronizer: ./sa/synchronizer.json
udca: ./sa/udca.json
如要套用更新,您只需要套用 runtime 元件,如下所示:
apigeectl apply -f overrides-file.yaml -c runtime
傳輸層安全標準 (TLS) 金鑰和憑證
建立新的虛擬主機時,您必須提供 TLS 金鑰和憑證。 金鑰/憑證用於與 Ingress 閘道進行安全通訊。
您可以自行決定如何為混合式設定產生適當的 TLS 憑證/金鑰配對。下列主題僅供參考,主要用於試用或測試新的混合式安裝,如果無法以其他方式取得 TLS 憑證,則可參考這些主題:
- 如需建立授權 TLS 憑證/金鑰組的範例步驟,請參閱「取得 TLS 憑證」。
- 您只能使用自行簽署的憑證/金鑰組合進行測試。請參閱「產生自行簽署的傳輸層安全標準 (TLS) 憑證」。