1

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!!

MacUsers
  • 449
  • 2
  • 7
  • 13
  • Why not leave the original Host header intact in haproxy and just use nginx as the backend? – wurtel Feb 05 '19 at 15:55
  • Well, that's by design and I gave here the simple version of my setup. There are 100s of sub-domains (e.g. bob.mywebsite.com, alice.mywebsite.com), which I don't have much control over. Every single request goes through the AWS Application LB (before going to php app-server), only allows the main.company.net host_header. But application understand what to serve, looking at the host part of the header. Hence I'm sending the 'host' bit as the custom_header, to get re-assembled on the app-server. -S – MacUsers Feb 06 '19 at 10:09
  • anyone else, have any idea? How do I do that? – MacUsers Feb 06 '19 at 21:45

0 Answers0