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 just installed Apache 2.2, and am trying to have two domains hosted on the same server configuration. I first created a Virtual Host (a.com), and debugged my configuration so that it was working. When I tried to add virtual host b.com, and tried to access it, all I get is the correct page for a.com. Both Virtual Hosts are pointed to the same static IP address. The server is running CentOS on a VPS.

/usr/local/apache2/conf/httpd.conf has the basic configuration, and is partly included below, but I have httpd.conf Include a second file, clients.conf that in turn Includes per-site configuration, which is in the home directories of the different websites. (Each site has their own account, with directories web, scripts, data, and config.)

httpd.conf:

Listen 80

NameVirtualHost [ip]
# [...]
Include /usr/local/apache2/conf/clients.conf

clients.conf:

Include /home/[a]/conf/apache/vhost.conf
Include /home/[b]/conf/apache/vhost.conf

/home/[a]/conf/apache/vhost.conf

<VirtualHost [ip]>
    ServerName www.[a].com
    ServerAlias [a].com
    ServerAdmin [me]@[a].com
    DocumentRoot /home/[a]/web/home
    ErrorDocument 404 "http://www.[a].com/error/?404"

    <Directory /home/[a]/web/home>
        Options -Indexes FollowSymLinks
        # Don't allow any .htaccess files
        AllowOverride None
        # Allow everyone to access
        Order allow,deny
    </Directory>
</VirtualHost>

/home/[b]/config/apache/vhost.conf

<VirtualHost [ip]>
ServerName www.[b].com
ServerAlias [b].com
ServerAdmin admin@[b].com
DocumentRoot /home/[b]/web/home
ErrorDocument 404 "http://www.[b].com/error/?/404/"

<Directory /home/[b]/web/home>
    Options -Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>
<VirtualHost [ip]>
ServerName beta.[b].com
DocumentRoot /home/[b]/web/home

<Directory /home/[b]/web/home>
    Options -Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

(Sorry for all the code, but I didn't know how much was needed.)

Might anyone see a problem in my code? I think that it looks almost identical to the VirtualHost Example (first one), except that I have expanded the "Other directives here" and have used full IP addresses, rather than the * wildcard, which is described in the "Note:" below the example.

Edit:

As suggested by a comment, I tried apachectl -S, which gave the following output:

# /usr/local/apache2/bin/apachectl -S
VirtualHost configuration:
[ip]      is a NameVirtualHost
         default server www.[a].com (/home/[a]/conf/apache/vhost.conf:5)
         port 80 namevhost www.[a].com (/home/[a]/conf/apache/vhost.conf:5)
Syntax OK

Shouldn't [b].com be showing up here?

share|improve this question
    
Does the output from 'apachectl -S' give you any clues? The script may also be called 'apache2ctl'. –  agy Jul 1 '11 at 0:27
    
@agy - I think it might, but I don't really know what to do now. I updated my post with the output. Could you take a look? –  Ryan Leonard Jul 1 '11 at 1:02

2 Answers 2

That [b].com isn't showing up is an indication that [b] is either not loading or not getting recognized (and typically the latter). The most common cause for this is a mismatch between the IP listed as part of your NameVirtualHost and the IP listed in <VirtualHost>; this is one reason why using *:80 is generally advisable.

At any rate, there's an easy test to see whether the file is being loaded: just include an invalid configuration command in [b].com's config file, and see whether httpd -t (or service httpd configtest, since you're on CentOS) reports an error.

share|improve this answer
    
I have looked over the IP addresses again, and they all match. I tried sticking in a command that has failed in other conf files, and nothing has shown up in Apache's error files, and httpd returned "Syntax OK", but the [b] conf file is included like [a]s. –  Ryan Leonard Jul 1 '11 at 1:20
    
I humbly suggest that the [b] conf file is not, in fact, being included, based on the facts as presented here. What do you get when you comment out the include for [a]… does httpd -S still show [a] as the default VHost? If so, you've got some crazy Includes. If not, if [b] shows up, you've got some sort of conflict. If neither shows up, then, to paraphrase a great man, "These are not the Includes you are looking for." –  BMDan Jul 1 '11 at 1:25
    
Random suggestion of the day: check whether the lineendings on the .conf file where you're running your Includes are, by any chance, in DOS format (file will do this for you: ASCII text, with CRLF line terminators means DOS format). –  BMDan Jul 1 '11 at 1:28
    
I also came to the conclusion that [b] is not included, httpd -S hasn't changed. All of the files have been edited with Smultron on a Mac, so the file endings "should" be the same. (Famous last words, I know) Actually, I did check, and it returned ASCII English text on clients.conf –  Ryan Leonard Jul 1 '11 at 10:47
up vote 0 down vote accepted

I figured out the solution to my problem while trying BMDan's suggestion. I opened up clients.conf, which should have been (and was saved as) including files from client a and b. Instead, all it had was the include for a. I have no clue why it didn't contain the right data, but my Apache install is now working properly.

My thanks go out to everyone who has helped me on this problem, and I apologize if the problem was an error that I made.

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.