Forum Moderators: phranque

Message Too Old, No Replies

Wonky Virtual Host issue

         

chardie

3:43 pm on Apr 18, 2005 (gmt 0)



Hi,

I'm having difficulty setting up two virtual hosts on my Mac server. My directives look like this (real IPs and addresses changed to protect the guilty) -

##############
NameVirtualHost 66.***.211.94:16080

<VirtualHost 66.***.211.94:16080>
ServerName example.com
DocumentRoot "/Users/example/sites"
</VirtualHost>

<VirtualHost 66.***.211.94:16080>
ServerName example2.com
DocumentRoot "/Users/example2/sites"
</VirtualHost>
###############

In this setup, all requests to both example.com and example2.com will be served from "/Users/example/sites"! And if I place example2.com's VirtualHost directive at the top, then both sites will be served from "/Users/example2/sites". Anyone have any idea how I can decouple the sites from each other?

Many thanks,

Chris

[edited by: jdMorgan at 5:54 pm (utc) on April 18, 2005]
[edit reason] Removed specifics per TOS. [/edit]

sitz

10:58 pm on Apr 18, 2005 (gmt 0)

10+ Year Member



Apache serves up content based on the first configured <VirtualHost> block if it doesn't find <VirtualHost> block containing a ServerName (or ServerAlias) which matches the Host: header of the incoming request.

Are you accessing using 'example.com' and 'example2.com' or 'www.example.com' and 'www.example2.com'. ServerName is fairly specific; it has to match the hostname /exactly/. If you're trying to access using 'www.example.com', add a ServerAlias:


NameVirtualHost 192.168.1.1:16080

<VirtualHost 192.168.1.1:16080>
ServerName www.example.com
ServerAlias example.com
(...other directives here)
</VirtualHost>

<VirtualHost 192.168.1.1:16080>
ServerName www.example2.com
ServerAlias example2.com
(...other directives here)
</VirtualHost>

No, it doesn't matter which hostname goes to ServerName and which goes to ServerAlias. This solution may or may no fix the issue, but whatever the problem is, I can pretty much guarantee you (heh. famous last words, those.) that your request isn't matching on one of the <VirtualHost> blocks for /some/ reason.

Other possibilities:

  • You're listening on multiple ports and you're not accessing the server on port 16080
  • You're listening on multiple IPs and you're not accessing the server on the IP used in your NameVirtualHost
  •