How to setup Apache2 web server to host multiple sites on 1 IP address

It’s very common these days to host multiple websites on a server using only a single IP address.
This is done with the Apache web server using ‘Virtual Hosts’.

You must first make sure that you have configured DNS to point whatever domains you wish to host on the server to the server’s IP address.

In your httpd.conf file (or a separate file that is included from the httpd.conf file) you will need lines similar to the following.
* Note: the ‘Listen 80′ will usually already exist in a default Apache installation

————————————————-

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName example1.com
ServerAlias www.example1.com
ErrorLog logs/example1.com-error_log
CustomLog logs/example1.com-access_log common
# Other directives here
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName example2.com
ServerAlias www.example2.com
ErrorLog logs/example2.com-error_log
CustomLog logs/example2.com-access_log common
# Other directives here
</VirtualHost>

————————————————-

Because example1.com is first VirtualHost in the configuration file, it will automatically be the default or primary server. That means that if a request is received for a domain that does not match one of the specified ServerName directives, it will be served by this first VirtualHost.

Once you have added these settings restart Apache and test.

-------------------------

Related Posts in Computer / Servers

One Response to “How to setup Apache2 web server to host multiple sites on 1 IP address”

  1. Cynthia Gould Says:

    bp34w5dob6iy4gak

Leave a Reply


Copyright 2007 HowtoMonster.com
Freelance Server Administration | The Musicians Network | www.techshoot.net | Social Network User Search