Alternative for nginx feature redirect on ssl error (http code 497)

When using nginx I can just use the 497 error code specific to nginx

497 HTTP Request Sent to HTTPS Port

and redirect to https with this rule:

error_page 497 https://$host:$server_port$request_uri;

When using haproxy the only solution so far is to use two ports e.g. port 80 and 443 but I only have one port (8443).

I tried the errorloc option but when a client tries to connect to the https port I get an ssl handshare error that can not be catched with the errorloc option.

Idealy I would use the following but that does not work:

frontend http-in
    bind :8443 ssl crt /usr/local/etc/haproxy/ssl/fullchain.pem alpn h2,http/1.1
    redirect scheme https code 301 if !{ ssl_fc }
    maxconn 50

    default_backend backend-server

Okay there is already a similar question which solves this question, you can find it here.

1 Like