Welcome to WebmasterWorld Guest from 54.196.244.45

Forum Moderators: bakedjake

Message Too Old, No Replies

name-based virtual hosting on apache

     
9:00 am on Feb 28, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 28, 2003
posts:3
votes: 0


I need to configure two different web site on one IP. What ammendment should i do on the httpd.conf and my DNS server?
9:06 am on Feb 28, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 7, 2003
posts:1230
votes: 0


hi zamnik,

the apache group has this in their docs for apache webserver. there is an intro on the topic in a whole article. it's called Apache Virtual Host documentation [httpd.apache.org].

i think you should read this. anyway, for domain name based virtual hosting, the following directives are used:


...
Port 80
ServerName server.domain.tld

NameVirtualHost *

<VirtualHost *>
DocumentRoot /www/domain
ServerName www.domain.tld
...
</VirtualHost>

<VirtualHost *>
DocumentRoot /www/subdomain
ServerName www.sub.domain.tld
...
</VirtualHost>

this example is taken out of the docs and handles a toplevel domain and a subdomain. but much more is possible, ie you could setup multiple domains in one virtualhost section.

12:59 am on Mar 1, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 28, 2003
posts:3
votes: 0


thanks for the links. any configuration i need to do on my DNS server and how? thanks again
8:54 pm on Mar 1, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 12, 2002
posts:885
votes: 0


DNS just needs to resolve both domain names to the IP of your server. That's it.
12:10 am on Mar 3, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 28, 2003
posts:3
votes: 0


So, it's only to deal with httpd.conf for setting up name-based virtual server on apache?
12:42 am on Mar 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 12, 2002
posts:885
votes: 0


Assuming a BIND name server and Apache:

in your zone file:


* IN A 192.0.34.166
IN HINFO "p166mmx" "Debian 3.0"

@ IN A 192.0.34.166
IN HINFO "p166mmx" "Debian 3.0"

in httpd.conf:


NameVirtualHost 192.0.34.166:80
<VirtualHost example.com:80>
ServerAdmin webmaster@example.com
DocumentRoot /var/www/www.example.com
ServerName www.example.com
ServerAlias example.com
</VirtualHost>
<VirtualHost devel.example.com:80>
ServerAdmin webmaster@example.com
DocumentRoot /var/www/devel.example.com
ServerName devel.example.com
</VirtualHost>
<VirtualHost other.example.com:80>
ServerAdmin webmaster@example.com
DocumentRoot /var/www/other.example.com
ServerName other.example.com
</VirtualHost>

These are based on my own working zone file and httpd.conf fragments, munged to fit example.com rather than my own domain and IP addresses. The ":80" that shows up in my httpd.conf could be omitted in many circumstances - in my configuration it can't, because port 443 uses IP-based virtual hosts. (I've got more virtual hosts than you can shake a stick at.) The "DocumentRoot" paths are purely hypothetical, and should match whatever directory you're keeping the files in for that vhost. The zone file fragment would expect to be used for the zone 'example.com'.