2

I have a few websites - around 20. All of them are php application are currently hosted on a single machine in apache. Now with virtual host configurations I can host all of them with one single ELB (unless they need to be over HTTPS). I can easily route the incoming request to be server from appropriate directory.

However when I put create a CloudFront Distribution with Origin as ELB, all my websites start getting served the default page. How can I configure the apache to be CDN and ELB aware.

I thought I can use some headers but doesn't look like it would server anything. Following are the headers I am getting for a request when behind a CloufFront. CDN->ELB->MY_APPLICATION

"host": "MY_PUBLIC_FACING_ELB_DNS_NAME",
"cache-control": "cf-no-range-cache",
"user-agent": "Amazon CloudFront",
"via": "1.1 d6e48c0d02a2d98c0ccacee7577ee8c2.cloudfront.net (CloudFront)",
"x-amz-cf-id": "rB-gbTCqWq2IeZ-B25-d36rp9j3FmFuicsdPOltDBuYk0HPgLyLj_g==",
"x-forwarded-for": "54.169.155.12, 54.240.148.53",
"x-forwarded-port": "80",
"x-forwarded-proto": "http",
"connection": "keep-alive"

When not configured with ELB I get the following.

"host": "www.example.com",
"accept": "*/*",
"user-agent": "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36   (KHTML, like Gecko) Chrome/40.0.2214.91 Safari/537.36",
"accept-encoding": "gzip, deflate, sdch",
"accept-language": "en-US,en;q=0.8",
"cookie": "_sm_au=aaaaaaaaaaaaaaaaaaaa",
"via": "MY_SQUID_SERVER_NAME_VERSION",
"z-forwarded-for": "AAAAAAAAAAAA",
"cache-control": "max-age=259200",
"xroxy-connection": "keep-alive",
"connection": "Keep-Alive",
"x-forwarded-for": "MY_PROXY_SERVER'S_IP"

When hosted behind CloudFront, I don't get any host information passed on by Amazon's ELB. How do I get around this?

Thanks

2 Answers 2

6

From your problem description and headers you have posted I think you need to configure CloudFront distribution to pass Host header to origin. Take a look here: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web

2

You shouldn't need to configure Apache to be 'ELB / CF aware'

Have you added Alternate Domain Names (CNAMEs) entries to your Cloudfront Distribution configuration?

** Update **

Try forwarding your host header to the origin. You can do this by editing the behaviour(s), setting 'Forward Headers' to 'Whitelist' and adding 'Host' as a custom header, then allowing the changes to propagate.

1
  • Yes, I have CNAME entries in my distribution. All sites show the same page when CNAME entry for them is the Cloudfront Distribution's provided record. When the CNAME for these sites are of the ELB it works fine, but the moment I make these CNAME as that of CDN default page gets served. The origin for the distribution is my ELB's domain name.
    – ykesh
    Commented Feb 9, 2015 at 18:39

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