Traefik https redirection redirects to IP instead of Domain

I'm trying to use traefik in a VM which sits behind an nginx instance, which forwards any incoming traffic with http and https and the correct domain name to the VM. I want to set up traefik to redirect http to https in a docker-compose setup. My current config is

  reverse-proxy:
    image: traefik:v2.4
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"

      # http
      - "--entrypoints.web.address=:80"

      # redirect to https
      - "--entrypoints.web.http.redirections.entrypoint.to=websecure"

      # https
      - "--entrypoints.websecure.address=:443"

      # lets encrypt setup
      - "--certificatesresolvers.myresolver.acme.email=${ACME_EMAIL}"
      - "--certificatesresolvers.myresolver.acme.storage=/lets-encrypt/acme.json"
      # staging lets encrypt server
      - "--certificatesresolvers.myresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
      - "--certificatesresolvers.myresolver.acme.tlschallenge=true"
    ports:
      - "80:80"
      - "443:443"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
    depends_on:
      - pusher
      - front
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./lets-encrypt:/lets-encrypt

However, this doesn't work as expected, because it redirects from http://example.domain.com to https://xx.xx.xx.xx, i.e. the VMs ip address. How can I configure traefik to redirect to https://example.domain.com instead?

EDIT: formatting

Hi @tmahlburg

I think you will need to use proxyProtocol on your entrypoint(and nginx) when placed behind another proxy
https://doc.traefik.io/traefik/routing/entrypoints/#proxyprotocol

Hey,
thanks for the answer. I got it working another way: Setting "proxy_set_header Host $host" in the nginx configuration did the trick.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.