Virtual Hosts in Apache 2.2

Posted on December 4, 2006. Filed under: Hacks |

I installed apache 2.2 in c:/program files/apache software foundation/apache2.2.  The default domain was cause.in, and the default website was www.cause.in.

I needed to add a virtual host, like mysite.cause.in, and I needed the document root for that site to be in some other folder, other than c:/program files/…/htdocs.  I needed it to be in c:/www/docs/sites/mysite.

First off, in C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf, at the very bottom, there are these two lines:

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

What I do is remove the comment from the second line.

Then I open the httpd-vhosts.conf file… this is what I do to it.  Compare this with what you have in your vhosts.conf file.

#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
NameVirtualHost mysite.cause.in:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost mysite.cause.in:80>
    ServerAdmin webmaster@mysite.cause.in
    DocumentRoot /www/docs/sites/mysite
    ServerName mysite.cause.in
    ServerAlias mysite.cause.in
    ErrorLog logs/mysite.cause.in-error.log
    CustomLog logs/mysite.cause.in-access.log common
</VirtualHost>

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host2.cause.in
#    DocumentRoot /www/docs/dummy-host2.cause.in
#    ServerName dummy-host2.cause.in
#    ErrorLog logs/dummy-host2.cause.in-error_log
#    CustomLog logs/dummy-host2.cause.in-access_log common
#</VirtualHost>

Finally, I go back to the httpd.conf file and add a Directory directive just below the Directory directive for htdocs and above the IfModule dir_module.

<Directory “C:/www/docs/sites”>
 Order allow,deny
 Allow from all
</Directory>

I create a dummy index.html in c:/www/docs/sites/mysite, and restart apache:

net stop apache2.2

net start apache2.2

Then I open my hosts file, from c:\windows\system32\drivers\etc in notepad and add these two lines.

192.168.1.2 www.cause.in
192.168.1.2 mysite.cause.in

here 192.168.1.2 is my computers ip. you can set it 127.0.0.1 and you will see it work on your pc.

I open my browser and say http://mysite.cause.in and I see the results from the new folder.

Advertisements

Make a Comment

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

  • Posts

  • del.icio.us

  • Blog Stats

    • 77 hits
  • Meta Information

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: