A bit of background:
When abc.mywebsite.com (or xyz.mywebsite.com and so on) is requested, it received by haproxy, which replaces the Host header with main.company.net
and also adds the X-Custom-Header as abc (or xzy). Then these two headers are passed on to Nginx, for sending over to the PHP app. Here I need to rewrite the $http_host to abc.company.net
(something like $http_x_custom_header.company.net
) keeping the original URL intact, for the php app to pick up the value from there. I tried with:
set $my_domain company.net;
set $sub_domain $http_x_custom_header;
rewrite ^/(.*)$ https://$sub_domain.$my_domain/$1 redirect;
which is redirecting the URL to abc.company.net instead and eventually failing as it's an internal domain. Any idea how can I do that? I tried several pages from google but most of them talking about some sort or URL redirection. Let me know if my asking is not very clear or you need additional info. Thanks in advance!!