Wednesday, December 20, 2017

iis - Serve websites from multiple servers behind a single IP

I have a network setup as illustrated below. A Windows Server 2012 R2 box with a public IP, with multiple CentOS 7 web servers behind it. Each CentOS box is a web server for multiple sites. The CentOS boxes are running Apache 2.4 and PHP 5.5.



Windows server with web servers behind



The DNS entries for all the sites point to the public IP of Win Server (1.2.3.4).



My question is: How do I most efficiently serve the sites from the CentOS boxes, through to end users?



I've been looking at IIS reverse proxies. Here's my current (super-clunky) solution:





  • Win Server gets a request for foo.com

  • The URL is re-written to com.foo.web1 and IIS includes a $_SERVER variable to feed PHP the correct URL (foo.com).

  • The Win Server hosts file says com.foo.web1 goes to the IP of Web1 (192.168.1.2)

  • Web1 has a vhost for com.foo.web1 which then serves all the stuff for foo.com.



This works but it feels like a horrible hack. Ideally, I'd like to avoid rewriting URLs. I just want to say foo.com? Send that request to 192.168.1.2. thing.com? send that to 192.168.1.3. That sounds just like DNS to me, but obviously I can't just tell the user to go to some internal IP. Maybe I actually need a forward proxy? I can't just forward port 80 because of the need to split requests between multiple servers.



I feel like this problem must have been solved before, but I can't figure it out. (I'm really a developer, not a sys-admin). Help would be much appreciated!




I dumped Win Server for Linux and used HAProxy



To save anyone who finds this from reading through all the comments, I ended up dumping Windows Server and using Linux with HAProxy. HAProxy is able to forward the requests without re-writing the URLs.



I haven't yet found a good solution for Windows, but I think this might be acceptable:



Re-write all URLs by adding a port, so:





  • foo.com -> foo.com:8081

  • bar.com -> bar.com:8081

  • thing.com -> thing.com:8082

  • stuff.com -> stuff.com:8082



Then, on the Windows Server:




  • Forward port 8081 to port 80 on Web1


  • Forward port 8082 to port 80 and Web2



This is untested.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...