Problem with redirection http to https. I lose the port of web-secure

Hi to all!

I have a port problem in Traefik v2.0 with redirecction http to https. This is my config:

#Static conf Traefik
#traefik.toml

[entryPoints.web]
   address = ":84"

[entryPoints.web-secure]
   address = ":444"

[entryPoints.traefik]
   address = ":8082"

.....

# Dinamic conf Traefik
# dynamic-conf.toml

[http.routers]
   [http.routers.router0]
      rule = "Host(`myhost`)"
      entrypoints = ["web"]
      priority = 100
      service = "jupiter-web"
      middlewares = ["redirect"]

   [http.routers.router1]
      rule = "Host(`myhost`)"
      service = "jupiter-web"
      entrypoints = ["web-secure"]
      [http.routers.router1.tls]

[http.middlewares]
   [http.middlewares.redirect.redirectScheme]
      scheme = "https"
      permanent = true

[http.services]
   [[http.services.jupiter-web.loadBalancer.servers]]
      url = "http://192.168.1.200:84"
      passHostHeader = true

[[tls.certificates]]
   certFile = "/certs/domain.crt"
   keyFile = "/certs/sslkey.key"

Web-secure its ok. When I go to https:myhost:444 the cerfificates works and the web page of destiny on my service its ok.

But when I go to http:myhost:84 the middlewares redirect to https:myhost. I lose the 444 port and the conection its not secure. The certificates SSL fails obviusly.

Can you help me with the problem?

Thank in advance!!

Regards,
Jose Manuel

Hello,

you have to use redirectregex instead of redirectScheme.

1 Like

Hi Idez!!

Can you post a sample for this redirectregex based on my config?

Thank you!! :raised_hands:t3:

Something like that:

[http.middlewares]
  [http.middlewares.redirect.redirectRegex]
    regex = "^http:\/\/([\w\._-]+)(:\d+)?(.*)$"
    replacement = "https://${1}:444/${3}"
    permanent = true

Hi!

I test it your solution but i have a parsing error on your regex. Dont work. I try this other one but still doesnt work.

[http.middlewares]
   [http.middlewares.redirect.redirectRegex]
      regex = "^http://myhost/(.*)"
      replacement = "https://myhost:444/${1}"
      permanent = true
[http.middlewares]
   [http.middlewares.redirect.redirectRegex]
      regex = "^http://myhost:84/(.*)"
      replacement = "https://myhost:444/${1}"
      permanent = true
1 Like

Wao!! Sorry! I forget put the 84 port on URL. Now Its works!!

Thanks for your help!!!!:raised_hands:t3: