Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've tried to setup CloudFront to point to an Elastic Load Balancer.

I can see the requests are reaching the web server (which as multiple Virtual hosts configured) however the requests always end up at the /var/www/error/noindex.html page.

If I remove CloudFront from the www DNS the sites work fine on apache though the ELB.

Also I have the CName www for each domain setup.

Any thoughts on why these CloudFront requests would arrive at the error page?

thx

share|improve this question

3 Answers 3

Cloudfront currently doesn't have the ability to pass the Host header back to the origin. Instead it passes the host specified in the Cloudfront distribution's origin field. So while viewing a page through ELB will properly pass the host name you provide in your browser back to your web instance (thus bringing up the correct virtual host), the same request made through Cloudfront through to ELB and on to your web instance will arrive at the web instance with the host name of the ELB. I know, frustrating.

They know about it (as of writing this); hopefully it's fixed soon:

https://forums.aws.amazon.com/thread.jspa?threadID=84588

share|improve this answer

The problem can be resolved by adding one step to the request process. Cloudfront will forward the "Origin Domain Name" as the "Host" header variable in the request. That is the information used by your Web server to decide which virtual host to use when serving content.

Let's assume you want to send your visitor to subdomain1.domain.com and subdomain2.domain.com and both of these are virtual hosts on the same Web server.

First create CNAME entries to your cloudfront distributions. Use one distribution for each subdomain like this:

subdomain1.domain.com. 300 IN CNAME d1234567890.cloudfront.net.
subdomain2.domain.com. 300 IN CNAME d0987654321.cloudfront.net.

Instead of pointing your Cloudfront distributions directly at the load balancer, use an intermediary address in the "Origin Domain Name". So your settings would look something like this for the Cloudfront distributions:

d1234567890.cloudfront.net
Alternate Domain Names(CNAMEs): subdomain1.domain.com
Origin Domain Name:  subdomain1-intermediary.domain.com

d0987654321.cloudfront.net
Alternate Domain Names(CNAMEs): subdomain2.domain.com
Origin Domain Name:  subdomain2-intermediary.domain.com

Now create additional CNAME entries that direct the intermediary addresses to your load balancer:

subdomain1-intermediary.domain.com. 300 IN CNAME LOADBALANCER.eu-west-1.elb.amazonaws.com.
subdomain2-intermediary.domain.com. 300 IN CNAME LOADBALANCER.eu-west-1.elb.amazonaws.com.

When the request passes through the load balancer and arrives at your server, it will see either subdomain1-intermediary.domain.com or subdomain2-intermediary.domain.com in the "Host" header of the request. All you have to do now is to define your virtual hosts. In IIS the rules would look like this:

<rule name="rule1">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_HOST}" pattern="subdomain1-intermediary.domain.com" />
  </conditions>
  <serverVariables>
    <set name="HTTP_HOST" value="subdomain1.domain.com" />
  </serverVariables>
  <action type="None" />
</rule>
<rule name="rule2">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_HOST}" pattern="subdomain2-intermediary.domain.com" />
  </conditions>
  <serverVariables>
    <set name="HTTP_HOST" value="subdomain2.domain.com" />
  </serverVariables>
  <action type="None" />
</rule>
share|improve this answer

this problem is now solved by Amazon.

Check this link: https://forums.aws.amazon.com/message.jspa?messageID=552969#552969

And this link: http://aws.amazon.com/blogs/aws/enhanced-cloudfront-customization/

share|improve this answer
    
"While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes" –  Jacob Jul 25 at 15:33
    
Ok, sorry. You need to create a whitelist with the headers you want to bypass in the Behaviours tab inside Distribution Settings. –  user3742266 Jul 26 at 17:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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