All Products
Search
Document Center

API Gateway:Configure the Host header

Last Updated:Nov 15, 2023

This topic describes how to configure the Host header and the priority of the Host header configurations in API Gateway.

Overview

The Host header specifies to which backend service API Gateway forwards requests if multiple web applications or sites reside on the same backend server, in which case the applications or sites share an IP address. For example:

  • The backend service of an API is of the virtual private cloud (VPC) type, and multiple applications or sites run in the associated VPC. In this case, the Host header is used to specify to which application or site API Gateway forwards a request.

1. Enable Pass Host Header for the API group

You can select Pass Host Header in the Request Header Pass-through Settings section of the API group details page. After you select Pass Host Header, API Gateway passes the Host header parameter in the request to the backend service to replace the backend host setting, such as a domain:port string. If you do not select Pass Host Header, API Gateway sends the Host header that you specify to the backend service.

image

2. Add the host constant parameter to the API definition

When you create an API, you can add a constant parameter named host. You must select Head for the Parameter Location column and set the domain name of the backend service as the value for this constant parameter.

image

3. Configure the Host parameter for the VPC access authorization

Log on to the API Gateway console. In the left-side navigation pane, choose Open API > VPCs. Select the region where the desired VPC is located and click Create Authorization. In the Create VPC Access dialog box, specify Host.image

4. Configure a host for the backend service

Log on to the API Gateway console. In the left-side navigation pane, choose Open API > Backend Services. Click Create Backend Service in the upper-right corner and create a backend service of the HTTP/HTTPS or VPC type. Only these two types support host configurations. After you create the backend service, find the backend service and choose Configure Backend Service and View Associated APIs in the Actions column. On the Backend Service Definition page, click a tab to select an environment, such as Test, and click Create in the upper-right corner to define the backend service URL and host.

image.png

5. Configure the Host header in a backend routing plug-in

You can use the httpTargetHostName or vpcTargetHostName parameter to specify the Host header. The configuration in a backend routing plug-in has the highest priority. For more information, see section 1.3 of Backend routing plug-in.

Priority of Host header configurations

If you configure the Host header in all five methods, the configurations take effect based on the following order of priority: backend routing plug-in > backend service configuration > VPC access authorization > API group configuration > API definition.

Note

After you select Pass Host Header for an API group, API Gateway passes the Host header parameter in the request to the backend service to replace the backend host setting, such as a domain:port string. Example:

If the Host header value is apigateway.test.com in a request, the backend service URL is backend.test.com, and Pass Host Header is enabled, API Gateway forwards the request to apigateway.test.com.