Search code examples
phpapacheamazon-cloudfrontamazon-elb

Multiple websites with Single CloudFront Distribution does not get routed


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


Solution

  • 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