本主題將說明虛擬主機設定。虛擬主機可讓 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
當收到 https://api.example.com/orders
等 API 呼叫時,要求會傳送至 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 金鑰和憑證。金鑰/憑證可用於與入口閘道進行安全通訊。
您可以自行決定如何為混合型設定產生適當的 TLS 憑證/金鑰組合。以下主題僅提供做為範例,主要用途是嘗試或測試新的混合式安裝作業,如果無法以其他方式取得 TLS 憑證:
- 如要瞭解建立授權 TLS 憑證/金鑰組的步驟,請參閱「取得 TLS 憑證」。
- 您只能將自行簽署的憑證/金鑰組合用於測試。請參閱「產生自行簽署的 TLS 憑證」。