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'm sure this is something I should already understand, but I'm finding myself confused.

The configs in play add up to this:

NameVirtualHost *:80
Listen 80

<VirtualHost *:80>
    <Directory />
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin@domain.tld
    ServerName domain.tld
    ServerAlias *.domain.tld
    DocumentRoot /var/www/domain.tld
    <Directory /var/www/domain.tld>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

DNS is working correctly.

The issue is, every variant of http://*.domain.tld/ (including http://domain.tld/) works correctly, except http://www.domain.tld/ which throws a 403.

The logs state: client denied by server configuration: /etc/apache2/htdocs

If I remove the first VirtualHost block from play, everything works as expected including http://www.domain.tld. This leads me to believe that for some reason, Apache is not considering www.domain.tld to match the second VirtualHost block, and is thereby falling back to deny all.

This seems wrong. Shouldn't the second block match www.domain.tld?


I've been able to resolve this, but I still don't understand why. In my original configs, I was using the real ip address of the server instead of *. Switching all instances to * as shown above made everything work as expected.

Does this have something to do with the way browsers request resources?

share|improve this question
    
What is the output of httpd -S? –  Mark Wagner Mar 28 '11 at 18:59
    
I don't seem to have that command. Ubuntu 10.10. ? –  Carson C. Mar 29 '11 at 13:08
    
Ubuntu calls it apache2 instead of httpd –  Some Linux Nerd Mar 27 at 21:05
add comment

1 Answer

I would avoid the wildcard for the www record.

Change this:

ServerName domain.tld

ServerAlias *.domain.tld

To this:

ServerName www.domain.tld

ServerAlias domain.tld subdomain.domain.tld etc.domain.tld

to see if that works. calling the Server name www.domain.tld for testing the wildcard to see if it's causing the problems.

share|improve this answer
    
I changed to just ServerName www.domain.tld ServerAlias domain.tld to simplify things. Same results unfortunately. As in, domain.tld works, www.domain.tld 403. –  Carson C. Mar 28 '11 at 17:11
    
What does "host www.domain.tld" give back as an IP address. Is it correct ? –  Jonathan Ross Mar 29 '11 at 6:16
    
Yes, all DNS resolution is correct, including reverse DNS. Please see my edit above. –  Carson C. Mar 29 '11 at 13:08
    
I haven't used wildcards like that in my Apache builds so I'm not sure but needless to say Apache can be a black art at times :-) (I've have some highly strange URL redirect issues in the past) Glad it's fixed anyway. –  Jonathan Ross Mar 29 '11 at 13:18
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.