Reputation: 338
Question update below!
I have set up traefik in the last days, it seems to work great for docker containers. What does not work is setting up a non-docker backend. I have a netdata dashboard running (https://github.com/netdata/netdata) on port 19999 on the host.
I have defined a file provider:
[providers.file]
directory = "/home/myname/traefik"
filename = "providers.toml"
watch = true
Where I defined the service and router for my netdata dashboard:
[http.routers]
[http.routers.netdata]
service = "netdata"
middlewares = ["replacepath"]
rule = "Host(`my.host.name`) && Path(`/netdata`)"
[http.middlewares]
[http.middlewares.replacepath.replacePath]
path = "/"
[http.services]
[http.services.netdata]
[http.services.netdata.loadBalancer]
[[http.services.netdata.loadBalancer.servers]]
url = "http://192.168.178.60:19999/" ---> my server local ip
I use replacepath to strip the path so I don't end up one directory further down, which is not existing.
However when I visit http://my.host.name/netdata it serves me only raw html by the looks of it, I get 404s for .css and .js content.
What do I have to do to get all files in the website directory delivered? I feel like there is an easy solution to this which I can't see right now...
I found several tutorials using older traefik versions, where they use frontends and backends, to my understanding these are being replaced by routers, middlewares and services.
Update #1, 30 Jan 20:
After some more tries and a failed attempt to make it work with nginx I realized that not the proxy itself is the problem here. I noticed that whatever service I run at root level (so, not path rules in traefik, or location /
in nginx) it works, but everything else which gets a path/location is broken or not working at all. One service I wanted to proxy via a route is a dashboard from my homebridge (https://github.com/nfarina/homebridge) - but it seems like Angular is having troubles with custom paths. Same problem with my netdata dashboard or my onionbox status site. I am leaving this question open, maybe someone finds a (hacky) way of making it work.
Upvotes: 4
Views: 2177
Reputation: 589
You must use "PathPrefix" on router and "replacePathRegex" on middleware.
Try this way... its work for me:
[http]
[http.services]
[http.services.netdata]
[http.services.netdata.loadBalancer]
[[http.services.netdata.loadBalancer.servers]]
url = "http://172.24.0.1:19999"
[http.middlewares]
[http.middlewares.rem_subfolder]
[http.middlewares.rem_subfolder.replacePathRegex]
regex = "/netdata/(.*)"
replacement = "/$1"
[http.routers]
[http.routers.netdata]
rule = "PathPrefix(`/netdata/`)"
entrypoints = [
"web",
"websecure"
]
middlewares = [
"rem_subfolder"
]
service = "netdata"
Run the following command to get your host ip (default route), and set at "url" from service.
docker exec -it traefik ip route
Remember to change bind to = *
to bind to = 172.24.0.1
at netdata.conf, to make it accessible only from traefik.
Upvotes: 1