Traefik frontend redirects doesn't work - traefik

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.

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

Jetty Service behind Traefik

I have a software package from a vendor that uses Jetty to provide web services. When I put Traefik infront of it and access the frontend I get redirected to the backend URL. For example the frontend URL is https://program.example.com/ and the backend (software) URL is http://192.168.1.1:8088/ when I browse to https://program.example.com/ i automatically get redirected to http://192.168.1.1:8088/. Thoughts?
[backends.sample]
[backends.sample.servers.sample]
url = "http://192.168.1.1:8088/"
[frontends.sample]
backend = "sample"
[frontends.sample.routes.sample]
rule = "Host:program.sample.com"
passHostHeader = true
useXForwardedFor = true
[frontends.sample.redirect]
entryPoint = "https"
permanent = true
I figured it out.
I had 'passHostHeader' in the wrong place.
[frontends.sample]
backend = "sample"
passHostHeader = true
[frontends.sample.routes.sample]
rule = "Host:program.sample.com"
useXForwardedFor = true
[frontends.sample.redirect]
entryPoint = "https"
permanent = true

Redirect Multiple Domains to external URLs in 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.

Traefik blue green deployment. Initialize web provider

I'm starting using traefik for blue/green deployment. I would like to use the REST API, so I have to put my configuration in the [web] section:
[web]
address = ":8080"
readOnly = false
[backends]
[backends.back]
[backends.back.loadbalancer.stickiness]
cookieName = "backend"
[backends.back.servers.S000]
url = "http://HOST_IP_ADDRESS:30000"
weight = 1
[backends.back.servers.S001]
url = "http://HOST_IP_ADDRESS:30001"
weight = 1
[frontends]
[frontends.front]
backend = "back"
passHostHeader = true
But it's not initialized with those values. However if I use PUT to http://localhost:8091/api/providers/web I can see the web provider OK. And if I use this same configuration for [file] it works right (but I'm unable to update it via API)
Is there any web to initialize [web] backends/frontends?
web section is deprecated.
try this:
# Enable API and dashboard
[api]
# Name of the related entry point
entryPoint = "traefik"
# Enabled Dashboard
dashboard = true