mf1
1
Hey guys.
I want to catch an old non-secured domain for a Redmine instance.
I have a Docker container with these labels:
labels:
- "traefik.enable=true"
- "traefik.http.routers.redmine.entrypoints=http"
- "traefik.http.routers.redmine.rule=Host(`sub1.host.de`)"
- "traefik.http.middlewares.redmine-https-redirect.redirectscheme.scheme=https"
- "traefik.http.routers.redmine.middlewares=redmine-https-redirect"
- "traefik.http.routers.redmine.rule=Host(`sub2.sub1.host.de`)" // 2nd domain
- "traefik.http.routers.redmine.middlewares=redmine-regex2"
- "traefik.http.middlewares.redmine2-regex.replacepathregex.regex=^sub2.sub1.host.de/(.*)"
- "traefik.http.middlewares.redmine2-regex.replacepathregex.replacement=https://sub1.host.de/$$1"
- "traefik.http.routers.redmine-secure.entrypoints=https"
- "traefik.http.routers.redmine-secure.rule=Host(`sub.host.de`)"
- "traefik.http.routers.redmine-secure.tls=true"
- "traefik.http.routers.redmine-secure.tls.certresolver=http"
- "traefik.http.routers.redmine-secure.service=redmine"
- "traefik.http.services.redmine.loadbalancer.server.port=3000"
- "traefik.docker.network=proxy"
How can I redirect the old domain sub2.sub1.host.de (http) to sub1.host.de (https)
Hello @mf1,
You can use the RedirectRegex
middleware for this.
This can be something like this:
labels:
- "traefik.http.middlewares.test-redirectregex.redirectregex.regex=^http://sub2.sub1.host.de/(.*)"
- "traefik.http.middlewares.test-redirectregex.redirectregex.replacement=https://sub1.host.de/$${1}"
mf1
3
I have to remove those lines and add you two lined at the end?
- "traefik.http.routers.redmine.rule=Host(`sub2.sub1.host.de`)" // 2nd domain
- "traefik.http.routers.redmine.middlewares=redmine-regex2"
- "traefik.http.middlewares.redmine2-regex.replacepathregex.regex=^sub2.sub1.host.de/(.*)"
- "traefik.http.middlewares.redmine2-regex.replacepathregex.replacement=https://sub1.host.de/$$1"
I've tried this but get only 404 page not found
.
Here's a simple example:
version: '3.9'
services:
traefik:
image: traefik:v2.6
command:
- --providers.docker
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
whoami:
image: traefik/whoami
labels:
traefik.http.routers.whoami.rule: Host(`sub1.localhost`) || Host(`sub2.sub1.localhost`)
traefik.http.routers.whoami.middlewares: test-redirectregex
traefik.http.middlewares.test-redirectregex.redirectregex.regex: ^http://sub2.sub1.localhost/(.*)
traefik.http.middlewares.test-redirectregex.redirectregex.replacement: https://sub1.localhost/$${1}
Which wields:
$ curl sub2.sub1.localhost -vvv
* Couldn't find host sub2.sub1.localhost in the (nil) file; using defaults
* Trying ::1:80...
* Connected to sub2.sub1.localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> Host: sub2.sub1.localhost
> User-Agent: curl/7.79.0-DEV
> Accept: application/json, application/xml, text/plain, */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 302 Found
< Location: https://sub1.localhost/
< Date: Tue, 08 Mar 2022 16:19:14 GMT
< Content-Length: 5
< Content-Type: text/plain; charset=utf-8
<
* Connection #0 to host sub2.sub1.localhost left intact
Found
$ curl sub1.localhost
Name: whoami
Hostname: 1236e601ba18
IP: 127.0.0.1
IP: 172.19.0.2
RemoteAddr: 172.19.0.3:55708
GET / HTTP/1.1
Host: sub1.localhost
User-Agent: curl/7.79.0-DEV
Accept: application/json, application/xml, text/plain, */*
Accept-Encoding: gzip
X-Forwarded-For: 172.19.0.1
X-Forwarded-Host: sub1.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: a7c4428ce953
X-Real-Ip: 172.19.0.1
mf1
5
Got it... Thx.
Here is my modified setup ...
labels:
- "traefik.enable=true"
- "traefik.http.routers.redmine.entrypoints=http"
- "traefik.http.routers.redmine.rule=Host(`sub1.host.de`, `sub2.sub1.host.de`)"
- "traefik.http.routers.redmine.middlewares=redmine-https-redirect"
- "traefik.http.middlewares.redmine-https-redirect.redirectscheme.scheme=https"
- "traefik.http.routers.redmine.middlewares=redmine-pub"
- "traefik.http.middlewares.redmine-pub.redirectregex.regex=^http://sub2.sub1.host.de/(.*)"
- "traefik.http.middlewares.redmine-pub.redirectregex.replacement=https://sub1.host.de/$${1}"
- "traefik.http.routers.redmine-secure.entrypoints=https"
- "traefik.http.routers.redmine-secure.rule=Host(`sub1.host.de`)"
- "traefik.http.routers.redmine-secure.tls=true"
- "traefik.http.routers.redmine-secure.tls.certresolver=http"
- "traefik.http.routers.redmine-secure.service=redmine"
- "traefik.http.services.redmine.loadbalancer.server.port=3000"
- "traefik.docker.network=proxy"