We want to forward all requests to domain.com/foo
to a S3 Bucket fronted by Cloudfront. The idea being that our domain is used while the content is loaded from S3/Cloudfront. I have Apache setup to reverse proxy requests to /foo
thusly:
<Location /foo>
RequestHeader set X-Forwarded-Proto "https"
ProxyPassReverseCookiePath / /foo
ProxyPass http://bar.cloudfront.net/
ProxyPassReverse http://bar.cloudfront.net/
</Location>
However when I hit domain.com/foo
I get a 403 Forbidden
from Cloudfront.
I tried adding the header RequestHeader set Host "bar.cloudfront.net"
, the page loads and I see the content in the s3
bucket, but then the domain is obviously the CDN domain.
Update:
I swapped out the cloudfront URL in the Apache config for the s3 bucket's public URL and it worked, while preserving the hostname. So I believe this confirms its an issue with Cloudfront.
I added our domain name as a CNAME on CloudFront. Then set the RequestHeader set Host
to our domain name with the /foo
. This preserves the host name but causes a 400
error from CloudFront.
Best Answer
Cloudfront needs to be aware of all Host headers it is going to receive. You can add domain.com as a CNAME entry in Cloudfront. This does not cause traffic to come to cloudfront, but it does identify that host header as related to your specific config.