i have apache config in ec2 instance as:
RewriteEngine On
ProxyPreserveHost On
ProxyRequests On
ProxyPass /blog http://212.128.122.142/blog
this works until i point my dns record to ELB but not if i change my DNS to point at CDN. either i get 502 or redirect loop.
I also tried rewrite rule as i saw 502 bad gateway was because CDN tries to access as
myendpoint.elb.amazonaws.com/blog
and that wont be served by Apache, so, i changed so that apache accepts orgin endpoint as serverAlias and rewrite cond to rewrite url back to original hostname, and passing it to IP with proxypreserve.
RewriteCond %{HTTP_HOST} !^(www\.)?mydomain\.com
RewriteCond %{HTTP_HOST} ^myendpoint.elb.amazonaws.com$
RewriteRule ^/blog http://mydomain/blog[R,L]
(i need to access /blog from different server hosted with same domain. And as mentioned above it all works until ELB is pointed to DNS Record but stops on CDN any heads up?)
What i am trying to achieve: host /blog in different server having this all working with cloudfront in top of ELB
I am answering my own question, so other can benefit from; Initially i thought this was issue with cloud-front and its mechanism. It turns out to be:
[After enabling loggin in both elb and cloudfront, i saw that]
If you point your domain to cloud-front, and cloud-front having origin as ELB [load balancer] it sends request to respective EC2 Instances, and your request for
example.com
would not go as example.com rather it will go as endpoint:cloud-front will send that request to elb as orginpoint so your url will be
myendpoint.elb.amazonaws.com
rather than example.com and it will request formyendpoint.elb.amazonaws.com:80/blog
, And main problem here was another reverse proxy that is siting infront of my blog server which couldn't understand the request, because nginx in that reverse proxy was configured to reject non-specified domains * to serve as 444.After that i didnt need rewritecond and rule as proxy pass would handle it happy :)