Page 1 of 1

Multiple virtual hosts issue.

PostPosted: 22. September 2010 11:18
by stefan24
Hi,

This is probably a topic that's been covered a million times, but I've read a great deal on the subject and have a half working solution using XAMPP, I have a osx machine at home and I've set everything up no problem so I'm a bit confused why the same operations don't work under XAMPP.

The probelm I have is if I set up two or more virtual hosts, when I try to access the site they default to the first declared site and I can't access any others. At the moment I have two sites listed if I try to access wordpress.local it resolves to sandpit.local which is incorrect and I'm not sure why?

Just to run through what I've done so far.

1. Switched on virtual hosting by un-commenting the line which C:\xampp\apache\conf\httpd.conf~
Include "conf/extra/httpd-vhosts.conf"

2. Added an entry into the hosts file to call back to the localhost
127.0.0.1 mySite.local
127.0.0.1 wordpress.local

3. Configured httpd-vhosts file, I've moved the main directory outside of the default xamp folder to another location.
But i've set up the directory locations plus given them permissions, but when I try to access the sites I can only access the first site in the list and not the second, which defaults to the first and I'm not sure why?

Here is the httd-vhosts.conf file
Code: Select all

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

<Directory "C:/Documents and Settings/stefan24/My Documents/My Dropbox/projects/SandPit">
  Order Deny,Allow
  Allow from all
</Directory>

#
# Use name-based virtual hosting.
#
##NameVirtualHost *: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 *:80>
    ##ServerAdmin postmaster@dummy-host.localhost
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.localhost"
    ##ServerName dummy-host.localhost
    ##ServerAlias www.dummy-host.localhost
    ##ErrorLog "logs/dummy-host.localhost-error.log"
    ##CustomLog "logs/dummy-host.localhost-access.log" combined
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin postmaster@dummy-host2.localhost
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.localhost"
    ##ServerName dummy-host2.localhost
    ##ServerAlias www.dummy-host2.localhost
    ##ErrorLog "logs/dummy-host2.localhost-error.log"
    ##CustomLog "logs/dummy-host2.localhost-access.log" combined
##</VirtualHost>








## ============= SandPit ===============


<VirtualHost sandpit.local>
  DocumentRoot "C:/Documents and Settings/stefan24/My Documents/My Dropbox/projects/SandPit"
  ServerName sandpit.local

  <Directory "C:/Documents and Settings/stefan24/My Documents/My Dropbox/projects/SandPit">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>



## ============= WordPress Blog ===============


<VirtualHost wordpress.local>
  DocumentRoot "C:/Documents and Settings/stefan24/My Documents/My Dropbox/projects/wordpress"
  ServerName wordpress.local

  <Directory "C:/Documents and Settings/stefan.burt/My Documents/My Dropbox/projects/wordpress">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>





Re: Multiple virtual hosts issue.

PostPosted: 22. September 2010 17:54
by stefan24
I figured it out what I was missing was the following statements.

ServerName 127.0.0.1
NameVirtualHost *:80

I then removed the IP address from the virtual host instructions and replaced it with a wildcard and the port 80.

<VirtualHost *:80>
DocumentRoot "<-- Directory Location -->"
ServerName <!-- site name -->
</VirtualHost>

cheers,

Stefan