AWS - Network Load Balancer - HAProxy. Redirect to 443 port

Hi.

  1. Network Load Balancer is configured on AWS and listens to ports 80 and 443. Through TargetGroup, packets are sent to EC2-instance via the 443 TLS port. The domain’s SSL certificate is attached to it. HAProxy is installed and configured on EC2-instance. HAproxy forwards requests to backend servers with nginx. If you type in the browser https://example.com or http://example.com then everything works. If you configure the http->https redirect in the HAProxy configuration, the site falls into the ERR_TOO_MANY_REDIRECTS error. This was the first configuration.
  2. Changed the configuration. I removed the certificate from NLB in AWS and registered in Listener port 443 in TCP, not in TLS. Then the situation is - https://example.com works, and http://example.com it doesn’t work by falling into an error.
  3. Then I configured NLB that HealthCheck for Target Group goes on TCP port 80, and not on 443. And to my surprise, the site started to fall into the error ERR_SSL_PROTOCOL_ERROR (redirect from http to https works).
    How do I correctly configure a redirect to SSL on NLB via HAProxy?

HAProxy config:

global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon

# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private

# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
#  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
# An alternative list with additional directives can be obtained from
#  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3

defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

frontend www-http
bind *:80
reqadd X-Forwarded-Proto:\ http
default_backend www-backend

frontend www-https
bind *:443 ssl crt /etc/ssl/private/example.pem
reqadd X-Forwarded-Proto:\ https
default_backend www-backend

backend www-backend
redirect scheme https if !{ ssl_fc }
server www-1 IP:443 check ssl verify none

Thank You.