[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-21 (世界標準時間)。"],[[["\u003cp\u003eThis document details how to configure virtual hosts in Apigee hybrid to manage API requests across multiple domain names and route proxy basepaths to different environments.\u003c/p\u003e\n"],["\u003cp\u003eVirtual host names must be unique, contain no more than 253 characters, consist only of lowercase alphanumeric characters or hyphens, and start and end with an alphanumeric character.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003evirtualhosts.routingRules[]\u003c/code\u003e configuration property determines which environment specific API proxy base paths are routed to, and you can add new environments by modifying the \u003ccode\u003eenvs[]\u003c/code\u003e property and updating the \u003ccode\u003eroutingRules\u003c/code\u003e accordingly.\u003c/p\u003e\n"],["\u003cp\u003eMultiple virtual hosts can be created, each with its own unique set of host aliases, and any changes to the virtual host configurations are applied using the \u003ccode\u003eapigeectl apply\u003c/code\u003e command targeting the runtime component.\u003c/p\u003e\n"],["\u003cp\u003eWhen setting up a new virtual host, you must provide TLS key and certificate, and the document provides links to obtaining authorized credentials, as well as self-signed options for testing purposes.\u003c/p\u003e\n"]]],[],null,["# Configure virtual hosts\n\n| You are currently viewing version 1.2 of the Apigee hybrid documentation. **This version is end of life.** You should upgrade to a newer version. For more information, see [Supported versions](/apigee/docs/hybrid/supported-platforms#supported-versions).\n| **NOTE:** The `virtualhosts` configuration is new in version 1.2.0. The virtual host `name` must:\n|\n| - contain no more than 253 characters\n| - contain only lowercase alphanumeric characters or a hyphen `-`\n| - start with an alphanumeric character\n| - end with an alphanumeric character\n\n\nThis topic discusses virtual host configuration. Virtual hosts allow Apigee hybrid to handle\nAPI requests to multiple domain names and route proxy basepaths to specific environments.\n\n\nTo specify which environment specific API proxy base paths should be routed to, use the\n`virtualhosts.routingRules[]` configuration property. For details on the\nindividual properties, see [virtualhosts](/apigee/docs/hybrid/v1.2/config-prop-ref#virtualhosts)\nin the Configuration property reference. For example: \n\n```\n...\n\nvirtualhosts:\n - name: vhost-one\n hostAliases: [\"api.example.com\"]\n sslCertPath: ./certs/fullchain.pem\n sslKeyPath: ./certs/privkey.pem\n routingRules:\n - paths:\n - /orders\n - /items\n env: test1\n - paths:\n - /customers\n env: test2\n\nenvs:\n - name: test1\n serviceAccountPaths:\n synchronizer: ./sa/synchronizer.json\n udca: ./sa/udca.json\n - name: test2\n serviceAccountPaths:\n synchronizer: ./sa/synchronizer.json\n udca: ./sa/udca.json\n```\n\n\nWhen an API call comes in such as: `https://api.example.com/orders`, the request\nis sent to the `test1` environment's message processor. Similarly, if a request to\n`https://api.example.com/customers` comes in, it is routed to the `test2`\nenvironment.\n\nAdding a new environment\n------------------------\n\n\nTo add a new environment, add its configuration to the `envs[]` property, and\nadd a new `virtualhosts.routingRules.path` entry that specifies which base paths you\nwant to map to the new environment. In the following example, a new environment named\n`test3` is added, and the `routingRules` have been updated to\nroute two paths to the new environment: \n\n```\nvirtualhosts:\n - name: vhost-one\n hostAliases: [\"api.example.com\"]\n sslCertPath: ./certs/fullchain.pem\n sslKeyPath: ./certs/privkey.pem\n routingRules:\n - paths:\n - /orders\n - /items\n env: test1\n - paths:\n - /v0/hello\n - /httpbin\n env: test2\n - paths:\n - /v0/inventory\n - /v0/customers\n env: test3\n\nenvs:\n - name: test1\n serviceAccountPaths:\n synchronizer: ./sa/synchronizer.json\n udca: ./sa/udca.json\n - name: test2\n serviceAccountPaths:\n synchronizer: ./sa/synchronizer.json\n udca: ./sa/udca.json\n - name: test3\n serviceAccountPaths:\n synchronizer: ./sa/synchronizer.json\n udca: ./sa/udca.json\n```\n\n\nTo apply the update, you only need to apply the `runtime` component, as follows: \n\n```\napigeectl apply -f overrides-file.yaml -c runtime\n```\n\nAdding multiple virtual hosts\n-----------------------------\n\n\nThe `virtualhosts[]` property is an array, and therefore you can create more than\none. Each virtual host must contain a unique set of host aliases: no two virtual hosts\ncan share the same host alias. For example, the new virtual host `dev` handles\ntraffic sent to the `api.internal.com` domain. \n\n```\nvirtualhosts:\n - name: vhost-one\n hostAliases: [\"api.example.com\"]\n sslCertPath: ./certs/fullchain.pem\n sslKeyPath: ./certs/privkey.pem\n routingRules:\n - paths:\n - /orders\n - /items\n env: test1\n - paths:\n - /v0/hello\n - /httpbin\n env: test2\n - paths:\n - /v0/inventory\n - /v0/customers\n env: test3\n\n - name: vhost-two\n hostAliases: [\"api.internal.com\"]\n sslCertPath: ./certs/fullchain.pem\n sslKeyPath: ./certs/privkey.pem\n routingRules:\n - paths:\n - /orders\n - /items\n env: test1\n - paths:\n - /v0/hello\n - /httpbin\n env: test2\n - paths:\n - /v0/inventory\n - /v0/customers\n env: test3\n\nenvs:\n - name: test1\n serviceAccountPaths:\n synchronizer: ./sa/synchronizer.json\n udca: ./sa/udca.json\n - name: test2\n serviceAccountPaths:\n synchronizer: ./sa/synchronizer.json\n udca: ./sa/udca.json\n - name: test3\n serviceAccountPaths:\n synchronizer: ./sa/synchronizer.json\n udca: ./sa/udca.json\n```\n\n\nTo apply the update, you only need to apply the `runtime` component, as follows: \n\n```\napigeectl apply -f overrides-file.yaml -c runtime\n```\n| **NOTE:** If you only add or change the `virtualhosts` stanza, and nothing else, then you can apply those changes with the `--settings` flag: \n|\n| ```\n| apigeectl apply -f overrides-file.yaml --settings virtualhosts -c runtime\n| ```\n|\n| If you change virtualhosts and envs, then you must apply the change without using `--settings`,\n| like this, to update the runtime component fully: \n|\n| ```\n| apigeectl apply -f overrides-file.yaml -c runtime\n| ```\n\nTLS keys and certificates\n-------------------------\n\nWhen you create a new virtual host, you must provide a TLS key and certificate.\nThe key/cert are used to provide secure communication with the ingress gateway.\n\n\nIt is up to you how you generate proper TLS certificate/key pairs for your hybrid\nconfiguration. The following topics are provided as samples only, intended primarily\nfor trying out or testing a new hybrid installation if it isn't feasible to obtain\nTLS credentials in another way:\n\n- See [Obtain TLS credentials](/apigee/docs/hybrid/v1.2/lets-encrypt) for a set of sample steps for creating an authorized TLS certificate/key pair.\n- You can use a self-signed certificate/key pair(s) for testing purposes only. See [Generate self-signed TLS credentials](/apigee/docs/hybrid/v1.2/environment-self-signed-tls)."]]