I am testing locally with curl and without a Host header "curl http://0.0.0.0/remote_api"
My remote api is receiving requests with the Host "0.0.0.0" and therefore it is unable to route my request. Is there a way to tell the loadbalancer to use a specified Host header?
I've tried a few things including a middleware to add a custom Host header but it did not work.
I have the following setup:
[http.services]
[http.services.remote_api.loadBalancer]
[[http.services.remote_api.loadBalancer.servers]]
url = "https://remote_api.example.com/"
Hello @mbarany,
First, When you are using curl locally, curl will use your target host (in this case 0.0.0.0
) and it will use it as the host header.
If you want to use a specific host header, add a DNS entry for it into your local DNS resolver or host file, like 127.0.0.1 example.com
, and then use example.com/remote_api
as your request.
Note that if you use a custom host like example.com, you will need to ensure that your traefik router matches the host you are sending.
Secondly: When you set a backend URL that is a DNS name, the backend request will be made with that host header. Otherwise the backend request would not work properly.
If you want to proxy to a remote site, while preserving the original request host header, the backend URL has to be IP-based.
Thanks although I think I figured out my issue.
The solution is to add passHostHeader = false
on [http.services. remote_api.loadBalancer]
For some reason I had tried to add it to [[http.services.remote_api.loadBalancer.servers]]
instead, but after re-reading the docs I found my issue.
1 Like