2

I have Apache configure with several IP addresses:

Listen 111.111.111.111:80
Listen 111.111.111.111:443

Listen 222.222.222.222:80
Listen 222.222.222.222:443

Listen 333.333.333.333:80
Listen 333.333.333.333:443

(IPs are fake)

I have several VirtualHosts, one of which is a wildcard subdomain.

<VirtualHost *:80>
        ServerName *.example1.com
        DocumentRoot /var/www/vhosts/example1-wc/docs
</VirtualHost>

<VirtualHost *:80>
        ServerName www.example1.com
        DocumentRoot /var/www/vhosts/example1/docs
</VirtualHost>

<VirtualHost *:80>
        ServerName www.example2.com
        DocumentRoot /var/www/vhosts/example2/docs
</VirtualHost>

This works fine. Requests to www.example1.com are served under the example1 docroot, requests for example.example1.com are served under the example1-wc docroot and www.example2.com for example2 docroot.

I can change www.example2.com to use a specific IP without any problems however if I change the wildcard vhost *.example1.com to a specific IP:

<VirtualHost 111.111.111.111:80>
        ServerName *.example1.com
        DocumentRoot /var/www/vhosts/example1-wc/docs
</VirtualHost>

Then requests to www.example1.com create an infinite redirect loop on itself. This happens regardless of whether I use:

<VirtualHost 222.222.222.222:80>
        ServerName www.example1.com
        DocumentRoot /var/www/vhosts/example1/docs
</VirtualHost>

or

<VirtualHost *:80>
        ServerName www.example1.com
        DocumentRoot /var/www/vhosts/example1/docs
</VirtualHost>

Why is this happening and how can I get each virtualhost on its own IP?

2 Answers 2

2

I'm not sure if this is the root of your problem, but you should probably have the directives

NameVirtualHost 111.111.111.111:80
NameVirtualHost 222.222.222.222:80
NameVirtualHost 333.333.333.333:80

So the full configuration would have these directives in it:

Listen 111.111.111.111:80
NameVirtualHost 111.111.111.111:80
<VirtualHost 111.111.111.111:80>
    ServerName *.example1.com
    DocumentRoot /var/www/vhosts/example1-wc/docs
</VirtualHost>

Listen 222.222.222.222:80
NameVirtualHost 222.222.222.222:80
<VirtualHost 222.222.222.222:80>
    ServerName www.example1.com
    DocumentRoot /var/www/vhosts/example1/docs
</VirtualHost>

Listen 333.333.333.333:80
NameVirtualHost 333.333.333.333:80
<VirtualHost 333.333.333.333:80>
    ServerName www.example2.com
    DocumentRoot /var/www/vhosts/example2/docs
</VirtualHost>

but this should not appear anywhere:

NameVirtualHost *:80

Here's some further reading, if you're interested: http://httpd.apache.org/docs/2.2/vhosts/details.html (good luck making sense of it ;-)

1
  • If you check the /var/log/httpd/error.log or similar apache will warn you about overlapping vhosts. You should follow Davids advice to correct that error May 10, 2009 at 21:42
0

Just a wild guess, but have you tried putting the definition for the wildcard subdomain after the www.example1.com definition?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .