I have one server on which a domain abc com is hosted with nginx. The ssl certbot is also applied via nginx.
I have lxc container on that same machine in which a traefik is running.
I want to redirect traefik from xyz com to abc com. If i type in browser abc com it should give me xyz com
This is my static and dynamic configs.
## Static configuration
entryPoints:
http:
address: ":80"
https:
address: ":443"
certificatesResolvers:
myresolver:
acme:
email: shell@gmail.com
storage: acme.json
httpChallenge:
entryPoint: http
api:
dashboard: true # On port 8080
insecure: true
providers:
file:
# filename: /etc/traefik/dynamic.yml
# filename: /etc/traefik/tls.yml
filename: /etc/traefik/redir.yml
watch: true
log:
# filePath: "/var/log/traefik/trafik.log"
level: DEBUG
accessLog: {}
http:
routers:
to-runpod:
rule: "Host(`abc.com`)"
entryPoints:
- https
# middlewares:
# - redir
# - cors
service: runpodserv
tls:
certResolver: myresolver
services:
runpodserv:
loadBalancer:
servers:
- url: "https://xyz.com"
passHostHeader: true
Should Traefik show you the other site (proxy content) or really redirect (tell the browser to load another domain)?
Like i type abc.com and The content should get changed to xyz.com in browser not the url. Idk what is the best term for it.
Then that’s what your current config should do. Is it not working? What’s the error?
Note that many websites have precautions that this is not possible, with CORS headers and JS.
Do you use the correct filename in provider.file
to match your dynamic config file?
Yes it shows in logs that it loaded.
DEBU[2023-12-11T11:54:21Z] *file.Provider provider configuration: {"watch":true,"filename":"/etc/traefik/redir.yml"}
INFO[2023-12-11T11:54:21Z] Starting provider *traefik.Provider
Try to set passHostHeader: false
, otherwise Host header abc.com
will be sent to xyz.com
.
I set it false, but still same behaviour, i am really confused, whats going on.
Enable and check Traefik access log in JSON format.
This below configs works good, although the basic auth don't work as intended. Working on it
http:
routers:
to-runpod:
rule: "Host(`abc.com`) && Path(`/v1/chat/completions`)"
middlewares:
- redir
service: runpodserv
dashboard:
rule: "Host(`abc.com`) && PathPrefix(`/dashboard`)"
service: api@internal
middlewares:
- dashboard-auth
services:
runpodserv:
loadBalancer:
servers:
- url: "https://xyz.com"
passHostHeader: false
middlewares:
redir:
redirectRegex:
regex: "^https://abc.com/(.*)"
replacement: "xyz.com/${1}"
permanent: true
dashboard-auth:
basicAuth:
users:
- "admin:$Kanger"
basicAuth
uses a hashed password, not plain.
Yes ofc, thats not the reason actually i want to access my dashboard at abc com /dashboard, i can access the dashboard but it don't get any values.
Check the doc, you need /api
, too.
# Dynamic Configuration
labels:
- "traefik.http.routers.dashboard.rule=Host(`traefik.example.com`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
- "traefik.http.routers.dashboard.service=api@internal"
- "traefik.http.routers.dashboard.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
When you do setup your own routing for dashboard, you probably should not use insecure
:
api:
dashboard: true # On port 8080
insecure: true
1 Like