Nginx: modifying http_host header using the value from x_custom_header

1.1k views Asked by At

I've been trying to do this thing for while but nothing working out for me. Hoping if anyone here can help....

The php app here reads $_SERVER['HTTP_HOST'] and then judging host part of the header, it decides which site to serves. The issue here, Nginx receives the headers as $http_host = mainweb.prd.mydomain.net and $x_custom_header = bob (or alice, joe etc.). I need to [re]set the value for http_host to bob.prd.mydomain.net. I suppose I need to do something like this:

set $host_header "${x_custom_header}.prd.mydomain.net";
proxy_set_header Host $host_header;

But this is obviously not working. Any idea how can I do that. All of the example that I can see here is actually for URL redirection, which is actually changing the URL in the browser, which I absolutely don't want. Any idea how can I do that? Any pointer to the right direction will be very much appreciate.

-San

0

There are 0 answers