How do I configure CloudFront to forward the Host header to the origin?

Last updated: 2020-08-20

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?

Short description

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.

Resolution

Create a cache policy and an origin request policy

  1. Follow the steps to create a cache policy using the CloudFront console.
  2. Under Cache key contents, for Headers, select Whitelist. From the list of headers, select Host. Then, choose Add header.
  3. Complete all other settings of the cache policy based on the requirements of the behavior that you're attaching the policy to.
  4. Follow the steps to create an origin request policy using the CloudFront console.
  5. Under Origin request contents, for Headers, select Whitelist. From the list of headers, select Host. Then, choose Add header.
  6. Complete all other settings of the origin request policy based on the requirements of the behavior that you're attaching the policy to.
  7. After you create the cache policy and origin request policy, follow the steps to attach the policies to the relevant behavior of your CloudFront distribution.

Editing the settings of an existing behavior

  1. Open the CloudFront console, and then choose your distribution.
  2. Choose the Behaviors tab, and then choose the path for which you want to forward the Host header.
  3. Choose Edit.
  4. For Cache Based on Selected Request Headers, choose Whitelist.
  5. Under Whitelist Headers, choose Host from the column on the left, and then choose Add.
  6. Choose Yes, Edit.

Did this article help?


Do you need billing or technical support?