6

I am trying to add the "Host" header as a custom header when creating an Amazon Cloudfront Distribution. However, I always get the error "The parameter HeaderName : Host is not allowed".

I tried to edit the "Cache policy" by going to "Cache key settings" -> "Headers - Include the following headers" and add "Host" to the list. But this still didn't work. What is the problem?

1 Answer 1

5

Official docs says

You can’t configure CloudFront to add any of the following headers to requests that it sends to your origin:

  • Cache-Control

  • Connection

  • Content-Length

  • Cookie

  • Host

  • If-Match

  • If-Modified-Since

  • If-None-Match

  • If-Range

  • If-Unmodified-Since

  • Max-Forwards

  • Pragma

  • Proxy-Authorization

  • Proxy-Connection

  • Range

  • Request-Range

  • TE

  • Trailer

  • Transfer-Encoding

  • Upgrade

  • Via

  • Headers that begin with X-Amz-

  • Headers that begin with X-Edge-

  • X-Real-Ip

4
  • Thank you very much. Since my server uses virtual hosts to host multiple domains, the "Host" header is used to distinguish these domains. If Amazon does not allow me to send the "Host" header, then how can my server distinguish domains?
    – alancc
    Aug 27, 2021 at 1:11
  • it's prohibited(cant configure) because cloudfront already send the real/defined header. If you use cloudfront for example.com then you visit it, it will send example.com as host header to your server. Aug 27, 2021 at 1:22
  • Thank you. But currently I am in test phrase, I have not set the CNAME for the cloudfront distribution, so I access it via d2mamsrhkq8bo4.cloudfront.net, in such a case, will it still send the original domain name as the "Host" to the original server?
    – alancc
    Aug 27, 2021 at 1:26
  • yes, the original host header sent from the browser to cloudfront will be sent to your server too. Aug 27, 2021 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.