Personal tools
You are here: Home Wiki ConfigureApacheForVirtualHost
Views
ConfigureApacheForVirtualHost copied.

How to configure apache for virtual host?

A short tutorial by AmitChakradeo

http://httpd.apache.org/docs/vhosts/examples.html explains it much much better than this page.

Basically, this means even if you have a single IP address, you can serve different webpages for different domains. e.g. http://www.kernel-panic.org/, http://wiki.kernel-panic.org/ both have the same IP address, but the webpages look very different. Virtual host means more than this, but this should suffice for now.

If you have a very few hosts or subdomains, you can add the following to your httpd.conf (either in /usr/local/etc/apache/httpd.conf or locate httpd.conf):

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

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

Create the directory /www/domain and put all the HTML files, images in that directory. Create another directory, /www/subdomain and put all files for www.sub.domain.tld there. Ofcourse, the DNS must return the same IP address for both www.domain.tld and www.sub.domain.tld for this to work. You cannot just invent names and expect it to work automatically.

If you have many domains then you can go for dynamically configured mass virtual hosting which is explained here. This has a lot of advantages: you do not have to change the httpd configuration for new virtual host at all. You just create a directory (or a SymbolicLink?) for the new host at the right place and tweak the DNS to return correct IP and the apache the server just starts serving new content dynamically. Isn't that great?



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: