Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traefik : redirect all http to https #82

Closed
guidtz opened this issue Oct 27, 2021 · 4 comments
Closed

Traefik : redirect all http to https #82

guidtz opened this issue Oct 27, 2021 · 4 comments
Labels

Comments

@guidtz
Copy link

guidtz commented Oct 27, 2021

Hello,
I try to force all http traffic to https but it's not works. This is my docker-compose :

services:
traefik:
  image: traefik:v2.5
  ports:
    - 80:80
    - 443:443
  deploy:
    placement:
      constraints:
        - node.role == manager
        - node.labels.traefik == true
    labels:
      - traefik.enable=true
      - traefik.docker.network=traefik-public
      - traefik.http.middlewares.admin-auth.basicauth.users=admin:$$apr1$$eGxxeKwV$$unRwPb4cIWBlWF9ljg2gx1        
      # https-redirect middleware to redirect HTTP to HTTPS
      # It can be re-used by other stacks in other Docker Compose files
      - traefik.http.middlewares.https-redirect.redirectscheme.scheme=https
      - traefik.http.middlewares.https-redirect.redirectscheme.permanent=true
      # traefik-http set up only to use the middleware to redirect to https
      # Uses the environment variable DOMAIN
      - traefik.http.routers.traefik-public-http.rule=Host(`traefik.swm.aukfood.ovh`)
      - traefik.http.routers.traefik-public-http.entrypoints=http
      - traefik.http.routers.traefik-public-http.middlewares=https-redirect
      # traefik-https the actual router using HTTPS
      # Uses the environment variable DOMAIN
      - traefik.http.routers.traefik-public-https.rule=Host(`traefik.swm.aukfood.ovh`)
      - traefik.http.routers.traefik-public-https.entrypoints=https
      - traefik.http.routers.traefik-public-https.tls=true
      # Use the special Traefik service api@internal with the web UI/Dashboard
      - traefik.http.routers.traefik-public-https.service=api@internal
      # Use the "le" (Let's Encrypt) resolver created below
      - traefik.http.routers.traefik-public-https.tls.certresolver=le
      # Enable HTTP Basic auth, using the middleware created above
      - traefik.http.routers.traefik-public-https.middlewares=admin-auth
      # Define the port inside of the Docker service to use
      - traefik.http.services.traefik-public.loadbalancer.server.port=8080
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro
    - traefik:/certificates
  command:
    # Enable Docker in Traefik, so that it reads labels from Docker services
    - --providers.docker
    # Do not expose all Docker services, only the ones explicitly exposed
    - --providers.docker.exposedbydefault=false
    # Enable Docker Swarm mode
    - --providers.docker.swarmmode
    # Create an entrypoint "http" listening on port 80
    - --entrypoints.http.address=:80
    # Create an entrypoint "https" listening on port 443
    - --entrypoints.https.address=:443
    # Create the certificate resolver "le" for Let's Encrypt, uses the environment variable EMAIL
    - [email protected]
    # Store the Let's Encrypt certificates in the mounted volume
    - --certificatesresolvers.le.acme.storage=/certificates/acme.json
    # Use the TLS Challenge for Let's Encrypt
    - --certificatesresolvers.le.acme.tlschallenge=true
    # Enable the access log, with HTTP requests
    - --accesslog
    # Enable the Traefik log, for configurations and errors
    - --log
    # Enable the Dashboard and API
    - --api
  networks:
    - traefik-public

Do you have any idea why redirection is not works ?

Best regards

@mh3th
Copy link

mh3th commented Jan 20, 2022

@guidtz Hi!

--entrypoints.http.http.redirections.entryPoint.to=https
--entrypoints.http.http.redirections.entryPoint.scheme=https
--entrypoints.http.http.redirections.entrypoint.permanent=true

Let me know if it helps.

@tiangolo
Copy link
Owner

Thanks for the help all!

Copy link

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants