Setting up virtual hosts in apache ver 2.4.9 (WAMP, Windows 2012)

Hello, I have a wamp server running and my conf/extra/httpd-vhosts.conf configuration is as follows;

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

On my c:\xampp\apache\conf\extra\httpd-vhost.conf
#
# 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.

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

# for localhost to work properly
<VirtualHost *:80>
    DocumentRoot "c:\wamp\www"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
    <Directory  "c:/wamp/www">
        AllowOverride All
        Options Indexes FollowSymLinks
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "c:\wamp\www\folder01"
    ServerName demo.re-web.com
    ServerAlias demo.re-web.com
    ErrorLog "logs/mysite-error.log"
    CustomLog "logs/mysite-access.log" common
    <Directory  "c:\wamp\www\dds">
        AllowOverride All
        Options Indexes FollowSymLinks
        Require local
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "c:\wamp\www\folder02"
    ServerName stage1.re-web.com
    ServerAlias stage1.re-web.com
    ErrorLog "logs/mysite-error.log"
    CustomLog "logs/mysite-access.log" common
    <Directory  "c:\wamp\www\dds">
        AllowOverride All
        Options Indexes FollowSymLinks
        Require local
    </Directory>
</VirtualHost>

Open in new window


my hosts file is:
127.0.0.1       localhost
127.0.0.1       demo.re-web.com
127.0.0.1       stage.re-web.com
127.0.0.1       stage1.re-web.com
::1             localhost
::1             stage.re-web.com
::1             demo.re-web.com
::1             stage1.re-web.com

Open in new window


The issue I am having is that when is use stage1.re-web.com (or any of the other virtual sites ) the  site that always comes up is my localhost content and not the folder that I have pointed my virtual site to (folder 01 / folder 02). How can I correct this issue?

Thanks,
A
aej1973Asked:
Who is Participating?
 
InsoftserviceCommented:
Just change  ##NameVirtualHost *:80 to NameVirtualHost *:80
restart your service

And your problem is solved
0
 
Steve BinkCommented:
Apache matches virtual hosts in a first-match process.  In other words, it selects the first virtual host definition that matches IP and host name.  

Try disabling the default virtual host configuration found in your Apache installation, or having your definitions included before the default.
0
 
aej1973Author Commented:
When you say 'default Virtual host' do you mean the following lines?
<VirtualHost *:80>
    DocumentRoot "c:\wamp\www"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
    <Directory  "c:/wamp/www">
        AllowOverride All
        Options Indexes FollowSymLinks
        Require local
    </Directory>
</VirtualHost>

Open in new window

0
 
Steve BinkCommented:
That could be it.  You can check for sure by opening a command prompt, changing directories into your apache2\bin, and running:
httpd -S

Open in new window

The output of that command will list all the defined virtual hosts and their files, though not necessarily in order.  You can go through each of those to discover in what order they are being included, and modify that order if necessary.

Also, make sure you have a "NameVirtualHost *:80" somewhere in your config.
0
 
aej1973Author Commented:
Thank you all...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.