On my DNS provider I redirect http to https. It works well.
In the server, I use letsencrypt with a certificate over the domain with www and all requests with https and www work very well also.
I was searching quite a time in the forum with questions like this redirection-with-https/1693/3 and trying several configurations for the proxy but nothing works.
Well, you don’t really have anything in your frontend currently that would actually redirect requests from https://domain.com to https://www.domain.com. Your current acl www_match_acl only checks if www.domain.com is already being used.
In order to have the redirect working I would replace your frontend config (starting with the acl) with this:
acl no_www_acl ssl_fc_sni -i domain.com
http-request redirect location https://www.domain.com%[capture.req.uri] code 302 if no_www_acl
use_backend apptest_server if !no_www_acl
So, if https://domain.com was requested, then redirect to https://www.domain.com (keeping any additional path or query string elements, if present). Send to apptest_server otherwise.
This config only works with browsers supporting SNI, but pretty much everything these days does. Alternatively you could write the acl like this (note the exact match): acl no_www_acl hdr(host) -i domain.com
It didn’t work. I am certainly doing something wrong. I replaced acl section as you suggested and the resulting config (below) still does not work. Do you have any idea? Do I need to keep the acl www_match_acl so people connecting directly to www can access or with your snippet this is not necessary anymore?
I realized I didn’t answer.
First of all thank you for your feedback, you pointed me in the right direction.
If this can help others, my problem was that I had a “URL redirection” in the DNS that permanently redirected @ to https://www.domain.com. Changing this for a A record instead that pointed to the hosting machine, and configuring the redirection with haproxy instead was the solution.