Skip to content

apache virtual hosts

August 25, 2007

Configure virtual hosts

Common ways to setup the virtual hosts are:-
* Name based
* IP based

Name based
Name based virtual hosting is simpler, for which you need to configure your DNS server to map each hostname to the correct IP address and then configure the HTTP server to recognize the hostnames. For example:

# Ensure that Apache listens on port 80
Listen 80

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

<VirtualHost *:80>
DocumentRoot /var/www/mysite1
ServerName www.mysite1.com
# Other directives here
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /var/www/mysite2
ServerName www.mysite2.org
# Other directives here
</VirtualHost>

If you are testing the virual hosting on your local system, you have to add the relevant hostname in “/etc/hosts” file.

IP Based
For example:-
# Listen for virtual host requests on all IP addresses
NameVirtualHost 192.168.1.1:80

<VirtualHost 192.168.1.1:80>
DocumentRoot /var/www/mysite1
ServerName www.mysite1.com
# Other directives here
</VirtualHost>

<VirtualHost 192.168.1.1:80>
DocumentRoot /var/www/mysite2
ServerName www.mysite2.org
# Other directives here
</VirtualHost>

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: