0

nginx-proxy relies extensively on the use of the Host header. However, most browsers do not allow you to manually set the Host header. If you try, you will get the error Refused to set unsafe header "Host".

So how am I supposed to send a request from the browser to nginx-proxy?

J. Munson
  • 2,275
  • 2
  • 17
  • 22
  • Why do you need to manually set the Host header? – Richard Smith Apr 04 '19 at 14:57
  • Because my frontend is at `sampledomain.com` and it needs to be able to reach any number of arbitrary backend services via nginx-proxy. If my auth service has the `VIRTUAL_HOST` variable set to `auth.local`, then to reach that service I need to include a `Host` header set to `auth.local`. This works with curl, but the browser rejects it. – J. Munson Apr 04 '19 at 15:37

1 Answers1

0

A resolution to this question was reached here.

The tl;dr is that you can only have ONE docker service on the backend which has a VIRTUAL_HOST variable, and it must correspond with the domain that the frontend is using.

If you have multiple backend services, and therefore multiple VIRTUAL_HOSTS, you will need to set the HOST header dynamically on the frontend so nginx-proxy knows where to route your request. But, as we now know, this is not possible because browsers will not allow you to dynamically set the Host header.

My solution was to replace nginx-proxy with a vanilla nginx config and rely on URL namespacing for service routing rather than trying to set the Host header.

J. Munson
  • 2,275
  • 2
  • 17
  • 22
  • I am facing this issue too. Could you post your dockerfile(s) and nginx.conf, please. It would be good to have an example to look at. Could you also explain (and show within the nginx.conf or dockerfile) what `URL namespacing for service routing` means, please. – kkuilla May 08 '19 at 19:23