Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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 ;-)

share|improve this answer
    
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 –  Dave Cheney May 10 '09 at 21:42
add comment

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

share|improve this answer
add comment

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.