Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem with VirtualHosts which Apache 2.4.

If I navigate to ty1.dev, I get the site for af2.dev instead

If this was Apache 2.2, all I would need to add is NameVirtualHost *:80 but is ignored in 2.4.

error.log does not report any problems

What have I missed?

# httpd-vhosts.conf
<VirtualHost *:80>
    ServerName af2.dev
    ServerAlias af2.dev
    ServerAdmin user@host.dev
    DocumentRoot "c:/Users/Adam.Adam-PC/Sites/af2/web"
    <Directory c:/Users/Adam.Adam-PC/Sites/af2/web>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName ty1.dev
    ServerAlias ty1.dev
    ServerAdmin user@host.dev
    DocumentRoot "c:/Users/Adam.Adam-PC/Sites/ty1"
    <Directory c:/Users/Adam.Adam-PC/Sites/ty1>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        Require all granted
    </Directory>

</VirtualHost>
share|improve this question
    
What do you get from c:\path\to\apache.exe -S? – Shane Madden May 31 '12 at 4:52
up vote 2 down vote accepted

try putting a specific ip and port in your listen statement as well as your virtualhost blocks. So put:

listen 127.0.0.1:80

and in each of your virtualhost:

<virtualhost 127.0.0.1:80>
share|improve this answer

0 down vote

I find answer from here: http://alexking.org/blog/2007/11/01/apache-2-only-serves-first-virtual-host

Put 2 servername in same 1 VirtualHost tag as below:

<VirtualHost *:80>

ServerName beta-site-1.com

DocumentRoot “/Library/WebServer/beta-site-1”

ServerName beta-site-2.com

DocumentRoot “/Library/WebServer/beta-site-2”

</VirtualHost>

I ended up having issues with the second site because I had two VirtualHost tag blocks.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.