0

I have been searching and reconfiguring for 6 days now and have lost several clumps of hair.

PROBLEM:

I want 2+ virtual hosts on my ubuntu server (1 ip) BUT - Only the first "alphabetically" listed sites-enabled shows. 000-default
www.domain1.com
www.domain2.com

Individually they all work (if i a2dissite for each leaving 1)

CONFIG: - UBUNTU 10.10 Server - EC2 instance (dont shoot me for this part - hoping this isnt the issue!) - APACHE 2.2.16 - DNS my.domain.com - to my public ec2 dns (this works)

Virtual Hosts: # default

<VirtualHost *:80>
        DocumentRoot "/home/www/"
        <Directory />
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Satisfy all
        </Directory>
        <Directory /home/www>
        Options Indexes Multiviews FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
        </Directory>
        LogLevel debug
        ErrorLog /home/www/logs/error.log
        CustomLog /home/www/logs/access.log "combined"
</VirtualHost>

Virtual Host 1 - domain1

<VirtualHost *:80>
        ServerAdmin webmaster@domain1.com
        ServerName domain1.com
        ServerAlias domain1.com www.domain1.com
        # Indexes + Directory Root.
        DirectoryIndex index.php
        DocumentRoot "/home/www/www.domain1.com/"
        # Directory directive
        <Directory "/home/www/www.domain1.com">
                Options Indexes Multiviews FollowSymLinks
                AllowOverride none
                Order allow,deny
                Allow from all
        </Directory>
        # CGI Directory
        ScriptAlias /cgi-bin/ /home/www/www.domain1.com/cgi-bin
        <Location /cgi-bin>
                Options +ExecCGI
        </Location>
        # Logfiles
        LogLevel debug
        ErrorLog "/home/www/www.domain1.com/logs/error.log"
        CustomLog "/home/www/www.domain1.com/logs/access.log" combined
</VirtualHost>

I also have the above for domain2 in another document root with a different domain name

sym links are in place. apache2ctl -St shows the following -

VirtualHost configuration:
*:80       is a NameVirtualHost
         default server  (/etc/apache2/sites-enabled/000-default:4)
         port 80 namevhost  (/etc/apache2/sites-enabled/000-default:4)
         port 80 namevhost domain1.com (/etc/apache2/sites-enabled/www.domain1.com:4)
         port 80 namevhost www.domain2.com (/etc/apache2/sites-enabled/www.domain2.com:4)
Syntax OK

My ports.conf:

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    NameVirtualHost *.443
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

No changes from default to my apache2.conf and httpd.conf is empty.

I have tried the following (and about a hundred others):

It seems I have tried everything that everyone else is having issues with but nothing seems to fix mine.

Possibilities:

  1. EC2
  2. Permissions on the files - I changed everything to the apache2 user "www-data" - no dice.
  3. I am a dope...lets hope its that and one of you kind people point me to my issue. :)
Caleb
  • 11,813
  • 4
  • 36
  • 49
user762313
  • 11
  • 1

3 Answers3

1

Speaking about virtualhosts, we had the same problem for a project of ours. The Apache's "ServerName" directive isn't optional, it's mandatory to use. Apache has no such thing as a "default" virtualhost to load when it has no ServerName match. And if virtualhost servernames overlap, well, that's just going to give you problems. In the end in those cases Apache just decides what to do depending on its configuration files loading order. And if you try to contact the server through an unspecified address (ip address, or something not mapped on the virtualhost) it will load the first virtualhost he got a configuration loaded for that address. The correct way to do it all is to have virtualhosts detailing all of the possible servernames in ServerName and ServerAlias directive. See name based virtual hosting on apache, and consider carefully the evidenced note "Main host goes away".

stoned
  • 808
  • 5
  • 10
0

Is it possible that your ports.conf is failing due to the period used instead of colon?

<IfModule mod_ssl.c>
    NameVirtualHost *.443
    Listen 443
</IfModule>

Note the **.443* should be **:443* above.

Matt Beckman
  • 1,502
  • 18
  • 33
-1

Just guessing. Looking on result of apache2ctl -St, you have difference in output :

port 80 namevhost domain1.com 
port 80 namevhost www.domain2.com

Maybe you should also set domain2.com as ServerName (without "www" prefix)

Ruslan
  • 349
  • 1
  • 4