Redirect Multiple Domains to external URLs in Traefik - traefik

After reading the github issues related to this with a bunch of loose snippets, It's still completely unclear how to write simple 301 redirects in Traefik as I used to do in nginx like this:
server_name foo.com
return 301 https://bar.com
The plan is: redirect any request in http-scheme to https (same domain), regardless whether the domain exists or not like in nginx default host on port 80 with redirect 301 https://$host.
Then, matching the https-Host, return a redirect code with the new Location: - Header.
My base traefik.toml is:
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
minVersion = "VersionTLS12"
[acme]
email = "acme#mydomain.com"
storage = "/etc/traefik/acme/acme.json"
entryPoint = "https"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"
[file]
directory = "/etc/traefik/conf/"
watch = true
Now, how does a file in conf/ must look like to adopt the above nginx redirect? It's about ~300 domains which are hosted at another place, so no backend needed, and it must not be 302/rewrites to be SEO-conform.
This pr https://github.com/containous/traefik/pull/2570 seems to be near to what I want, but there's no documentation how to use it.

Related

Traefik reverse proxy manipulates content-type header leading to MIME type error

I have configured Traefik reverse proxy to connect to my application. When I hit my application directly (without any proxy) I am able to get all JS, CSS, HTML pages but if I try to connect to my application via Traefik reverse proxy I face MIME type error.
Basically Treafik proxy changes all content-type header values of response to text/plain value. I tried to change Traefik autodetect configuration to True and False but either of it didn't worked.
traefik.toml
defaultEntryPoints = ["http", "https"]
loglevel = "INFO"
[accessLog]
filePath = "access-log.log"
[log]
filePath = "traefik-log.log"
[tracing]
serviceName = "service_console"
# enable dashboard
[api]
dashboard = true
insecure = true
# Create entrypoint
[entryPoints]
[entryPoints.http]
address = ":8888"
# user file provider
[providers]
[providers.file]
filename = "traefik-dynamic.toml"
traefik-dynamic.toml
[http]
# Create route for http
[http.routers.router_console]
entryPoints = ["http"]
service = "service_console"
rule = "Path(`/`)"
# Create loadbalaner for serivces
[http.services]
[http.services.service_console.loadBalancer]
[[http.services.service_console.loadBalancer.servers]]
url = "https://172.18.80.32:1443/"
Please help to resolve this issue.
Thanks in advance.
Regards,
Rahul Kumbhar

Traefik 2.0 redirect

I would like to create a traefik v2 config file which redirects http://localhost:80 traffic to http://otherhost.example.com:8080.
defaultEntryPoints = ["http"]
[entryPoints]
[entryPoints.dashboard]
address = ":80"
[entryPoints.dashboard.redirect???]
scheme = "http"
port = "8080"
No dockers whatsoever.
Thanks,
Lorand.
That worked:
defaultEntryPoints = ["http"]
## Static configuration
[entryPoints]
[entryPoints.web]
address = ":80"
[providers]
[providers.file]
filename = "dynamic_conf.toml"
watch = true
And dynamic_conf.toml:
## Dynamic configuration
[http.routers]
[http.routers.Router-1]
# By default, routers listen to every entry points
rule = "Host(`localhost`)"
service = "my-service"
[http.services]
[http.services.my-service.loadBalancer]
passHostHeader = false
[[http.services.my-service.loadBalancer.servers]]
url = "http://example.com"
It had to be called with full url, like: http://localhost/index.html

Is it possible to have Traefik handle multiple certificates/ domains

My domain name jstock.co DNS, and SSL certificate are handled by Cloudflare.
I have the following traefik.toml
defaultEntryPoints = ["http", "https"]
[web]
address = ":8080"
[web.auth.basic]
users = ["admin:xxx"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
CertFile = "/app/cert.pem"
KeyFile = "/app/key.pem"
With the above setup, traefik able to re-route the following traffic to correct docker containers
https://notification.jstock.co/info/
https://iex.jstock.co/info/
https://intrinio.jstock.co/info/
...
Now, we have purchased another domain name wenote.me. Its DNS, and SSL certificate also handled by Cloudflare.
I was wondering, is it possible, to reuse existing Traefik, to handle traffic from wenote.me? If so, what should be traefik.toml looks like?
This is how it is being done.
defaultEntryPoints = ["http", "https"]
[web]
address = ":8080"
[web.auth.basic]
users = ["admin:xxx"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
CertFile = "/app/cert.pem"
KeyFile = "/app/key.pem"
[[entryPoints.https.tls.certificates]]
CertFile = "/app/wenote.me.cert.pem"
KeyFile = "/app/wenote.me.key.pem"

Traefik frontend redirects doesn't work

Hey i am trying catch all request to an Subdomain, with no matching rool and redirect them to https://localhost:8000 without subdomain and suburl. But there is no redirect, i just get the response from the backend.
[file]
[frontends]
[frontends.homeRedirect]
entryPoints = ["https"]
priority = 1
backend = "homeRedirect"
[frontends.homeRedirect.routes.everything]
rule = "PathPrefix:/"
[frontends.homeRedirect.headers]
SSLRedirect = true
[frontends.homeRedirect.redirect]
regex = "(.*)"
replacement = "https://localhost:8000"
[backends]
[backends.homeRedirect]
[backends.homeRedirect.servers]
[backends.homeRedirect.servers.server0]
url = "http://frontend:80"
Is there something wrong with my file?
In this case, a redirect on the entry point is more appropriate:
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
regex = "^http://subdomain.mydomain/(.*)"
replacement = "http://myotherdomain/$1"
https://docs.traefik.io/v1.5/configuration/entrypoints/#rewriting-url
localhost inside the Traefik container is the container not the real machine.

Is HTTP to HTTPS redirection configurable per frontend in the Træfik File backend?

According to https://github.com/containous/traefik/pull/2133, it should be possible to redirect selectively per frontend. Is this available in the File backend?
I tried adding the following, but it didn't work:
[frontends.foo.headers]
SSLRedirect = true
The option SSLRedirect = true always redirect on 443.
If you want to redirect to an entry point without using 443 port use entryPoint = "https"
https://docs.traefik.io/user-guide/examples/#http-redirect-on-https
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "examples/traefik.crt"
keyFile = "examples/traefik.key"
https://docs.traefik.io/configuration/backends/file/
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryPoints.http]
address = ":80"
# ...
[entryPoints.https]
address = ":443"
# ...
[file]
[frontends]
[frontends.frontend1]
backend = "backend1"
[frontends.frontend1.redirect]
entryPoint = "https"
# ...