homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

name-based virtual hosting on apache

 9:00 am on Feb 28, 2003 (gmt 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)

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 *>
DocumentRoot /www/subdomain
ServerName www.sub.domain.tld

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)

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)

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)

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)

Assuming a BIND name server and Apache:

in your zone file:

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

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

in httpd.conf:

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

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'.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved