How do I configure CloudFront to forward the Host header to the origin?
Last updated: 2021-10-26
The origin configured on my Amazon CloudFront distribution uses virtual hosting. Because of this, my distribution must forward the Host header to my origin server. How can I configure my distribution to forward the Host header?
To configure your distribution to forward the Host header to the origin, you can do one of the following:
- Create a cache policy and an origin request policy
- Edit the settings of an existing behavior in the distribution
Important: For Amazon Simple Storage Service (Amazon S3) origins, caching based on the Host header isn't supported. For more information, see Selecting the headers to base caching on.
Creating a cache policy and an origin request policy
- Follow the steps to create a cache policy using the CloudFront console.
- Under Cache key settings, for Headers, select Include the following headers. From the Add header dropdown list, select Host.
- Complete all other settings of the cache policy based on the requirements of the behavior that you're attaching the policy to, and then choose Create.
- After you create the cache policy, follow the steps to attach the policies to the relevant behavior of your CloudFront distribution.
Editing the settings of an existing behavior
- Open the CloudFront console, and then choose your distribution.
- Choose the Behaviors tab, and then choose the path that you want to forward the Host header to.
- Choose Edit.
- Under Cache key and origin requests, confirm that Legacy cache settings is selected. If it's not selected, then follow the steps in the preceding section to create a cache policy. If Legacy cache settings is selected, then complete the following:
For Headers, select Include the following headers.
From the Add header dropdown list, select Host.
- Choose Save Changes.