2

I have an amazon EC2 instance with two website site1.com and site2.com. The EC2 is behind an ELB (elastic load balancer) , the site1 and site2 point to the ELB. Now in apache to redirect correctly the users the to right website, i use vhosts. The problem is that apache uses ServerName to determine what website is called. With ELB, ServerName is always the same, because both site1 and site2 get ELB address before reaching apache, the ip and ports are also the same. So how you guys work around this ?

PS: i don't want to use two load balancer, because i will add more websites and having many load balancer costs too much.

EDIT I want to keep only port 80 for the reasons explained in +kums answer comment bellow.

john
  • 535
  • 7
  • 16
  • why do you need an ELB? – Dinesh Oct 27 '14 at 03:10
  • Found that `Host` header wasn't forwarded by ELB? Any updates since your question? – Martín Schonaker Apr 24 '15 at 21:28
  • I am not sure about apache, but I could do the exact same thing with nginx, and multiple vhosts, where the host is chosen by server name. ELB is not a problem, it should send the host name as the user inputs it in the browser. If there is some redirect, it's not ELB problem, but rather somewhere else, (some miss config in the server conf files, or even in the application level, for example wordpress adds redirect to "site_url" if you don't update it properly - via DB) – Cesc Nov 14 '18 at 11:30

1 Answers1

-1

Since you want to use the same EC2 instance for two different sites, use Apache port-based virtual hosts and configure ELB to have 2 listeners in different ports of the same EC2 instance. This idea is similar to having http site and https site on the same instance.

You can find the documentation here: http://docs.aws.amazon.com/gettingstarted/latest/computebasics-linux/getting-started-create-lb.html

kums
  • 2,661
  • 2
  • 13
  • 16
  • 1
    Sorry i didn't mention it before , but i don't want to listen to two different ports. I want to keep the port 80 because changing it will make my life harder : apache module that use port 80 will crash, Linux packages, firwalls, iptables will crash, api and webservices i provide will crash too, and too many things that i can't even imagine... – john Oct 19 '14 at 09:45