OpenVZ Forum


Home » General » Support » name based hosting
name based hosting [message #25019] Thu, 13 December 2007 02:16 Go to next message
Thomasd is currently offline  Thomasd
Messages: 39
Registered: December 2007
Member
I have looked all over on google, but came with bits and pieces of knowledge only.

I have this situation: with a single IP, I want to host several VPS.
Some services, like SSH can go on different ports, making everything easy.
But I would like also several apache servers, so they need to be on port 80. I do not care about https, etc. This is also a controlled environment, not reselling, etc which simplifies everything.

The only thing I could think of would be to use a proxy that translates: domain A.com goes to 10.0.0.1:80, domain B.com goes to 10.0.0.2:80 (10.0.0.1 and 10.0.0.2 being different VPS)

It would be great if someone that has done this would come up with a simple step-by-step so I can understand the process, as nothing on google really covered this from start to a working solution.


Re: name based hosting [message #25021 is a reply to message #25019] Thu, 13 December 2007 04:17 Go to previous messageGo to next message
ugob is currently offline  ugob
Messages: 271
Registered: March 2007
Senior Member
http://httpd.apache.org/docs/2.0/vhosts/name-based.html

Please read the manual before asking questions:
http://download.openvz.org/doc/OpenVZ-Users-Guide.pdf

Please have a look at the wiki before asking questions:
http://wiki.openvz.org/Main_Page
Re: name based hosting [message #25022 is a reply to message #25019] Thu, 13 December 2007 07:03 Go to previous messageGo to next message
Thomasd is currently offline  Thomasd
Messages: 39
Registered: December 2007
Member
how does this work when it comes to the nat part then?

let's assume I have two VPS (10.0.0.1 and 10.0.0.2) and each has apache listening to port 80, do I need to fw traffic from port 80 (on the main node) to both VPS and each decides if they want to handle it?

assuming my main ip is x.x.x.x,
iptables -t nat -A PREROUTING -p TCP -d x.x.x.x --dport 80 -j DNAT --to-destination 10.0.0.1
iptables -t nat -A PREROUTING -p TCP -d x.x.x.x --dport 80 -j DNAT --to-destination 10.0.0.2

is that correct?


From what I understand with the virtual host section, you have one apache server listening and then it dispatches the calls toweard the virtual hosts, but in this case we have several unrelated apache hosts, so how does this work?

[Updated on: Thu, 13 December 2007 07:06]

Report message to a moderator

Re: name based hosting [message #25023 is a reply to message #25019] Thu, 13 December 2007 07:54 Go to previous messageGo to next message
curx
Messages: 739
Registered: February 2006
Location: Nürnberg, Germany
Senior Member

Hi,

may this wiki post will (-> http://wiki.openvz.org/Shared_webhosting )

Re: name based hosting [message #25051 is a reply to message #25019] Thu, 13 December 2007 17:04 Go to previous messageGo to next message
rickb is currently offline  rickb
Messages: 368
Registered: October 2006
Senior Member
One way is to use an http proxy, such as pound, lighttpd, apache, nginx.

route all your port 80 traffic to VE 1, which runs one of the above. based on the domain, it will proxy the request to VE2, 3, etc depending on which domain is being requested.

Doing the IP translation in the kernel is the best, as VE2,3 see the actual request packets fromt he client, but the kernel would need to look at the packet data, such as using iptables layer 7 inspection module.

To my knowledge, the iptables modules in the general redhat distros cannot do this, so an http proxy would be my best suggestion.

Rick


-------------
Common Terms I post with: http://wiki.openvz.org/Category:Definitions

UBC. Learn it, love it, live it: http://wiki.openvz.org/Proc/user_beancounters
Re: name based hosting [message #25062 is a reply to message #25019] Thu, 13 December 2007 19:37 Go to previous message
Thomasd is currently offline  Thomasd
Messages: 39
Registered: December 2007
Member
so, if I take this example:

Apache VPS at 10.0.0.1 (a.com) and 10.0.0.2 (b.com)

should I create a proxy VPS, let's say at 10.0.0.3,

then forward port 80's traffic to it with:
ptables -t nat -A PREROUTING -p TCP -d m.y.i.p --dport 80 -j DNAT --to-destination 10.0.0.3

then, set apache (on 10.0.0.3) with:

VirtualHost m.y.i.p:80>
ServerName a.com
RewriteEngine On
RewriteRule ^(.*)$ http://10.0.0.1$1 [P]
RewriteRule ^(.*)$ http://www.a.com$1 [P]
</VirtualHost>

<VirtualHost m.y.i.p:80>
ServerName b.com
RewriteEngine On
RewriteRule ^(.*)$ http://10.0.0.2$1 [P]
RewriteRule ^(.*)$ http://www.b.com$1 [P]
</VirtualHost>

Is that correct?
Once I get it right, I think I'll write a wiki page about it Smile

[Updated on: Thu, 13 December 2007 19:37]

Report message to a moderator

Previous Topic: SSH to VE is very slow
Next Topic: ssh VPS doesn't work outsite Node server
Goto Forum:
  


Current Time: Thu Jul 18 12:24:32 GMT 2024

Total time taken to generate the page: 0.02474 seconds