0
votes

I had to create an SSL certificate for my domain “farmtrust.tn” using a CloudFront distribution that I've configured this way

  1. Set Origin Protocol Policy to HTTP Only

  2. Minimum Origin SSL Protocol to TLSv1.1_2016

  3. Changed origin to my EC2 instance Public DNS

  4. Set Viewer Protocol Policy to Redirect HTTP to HTTPS

  5. Finally add an Alias record for “farmtrust.tn” pointing to the CloudFront distribution URL.

Note : The connection between the user and the CloudFront URL is using HTTPS and the connection between the CloudFront and the Origin is using http.

Later, when I tried to GET request to the website “https://farmtrust.tn ” using the curl command, I noticed HTTP 302 response.

$ curl -IX GET https://farmtrust.tn 

HTTP/2 302 

content-type: text/html; charset=utf-8

content-length: 0

location: http://farmtrust.tn/ 

date: Mon, 23 Dec 2019 16:16:52 GMT

server: Apache/2.4.29 (Ubuntu)

x-cache: Hit from cloudfront

via: 1.1 87ba4da6c7513242d551023ab57badbf.cloudfront.net (CloudFront)

x-amz-cf-pop: MAN50-C1

x-amz-cf-id: BKFMLi_leVgG0Fniw0ZHYlp4fR8T2xJkhWsUs2x1nZRgr-ZnQ6eX-A==

age: 492

I have investigated further and I observed the following loop in routing.

https://farmtrust.tn —> CloudFront url —> EC2 Origin —>WebServer —> http://farmtrust.tn —> CloudFront redirects it to "https://farmtrust.tn ” —> ...

Now when I try to access the website I get ERR_TOO_MANY_REDIRECTS

With Prestashop there are some configurations which is redirecting these requests to a predefined URL. Which is located in tables ps_configuration and ps_shop_url

I'd like to know if I could stop this redirection somehow or what should I do.

Best regards,

2

2 Answers

0
votes

From the information I have , it seems like your origin server needs HOST header value as farmtrust.tn and CloudFront is sending the HOST header which you have defined in Origin configuration (EC2 DNS name).

Can you try to Whitelist HOST header in CloudFront and invalidate the cache and see if this works ?

This makes sense from below curl output(farmtrust.tn is currently pointed to EC2):

curl -vko /dev/null http://farmtrust.tn/fr/ -H "Host: ec2-35-180-3-55.eu-west-3.compute.amazonaws.com" 
Always 302 

curl -vko /dev/null http://farmtrust.tn/fr/
Returns 200
0
votes

I faced similer issue, below is what i did to resolve it -

1) We cant have http between cloudfront and origin and https between viewer and cloud front, this will fail with certificate mismatch error. so make your ec2 ssl first, use certbot for free ssl certificate.

2) once ec2 is ssl, create a load balancer elb, with http and https listeners.

3) in your cloud front point to elb as origin. and in route 53 point to cloud front.