2

I have just installed ubuntu (11.04).

I have installed apache/mysql/php etc.

I have a few sites sitting in

/var/www/site1
/var/www/site2
/var/www/site3

I want to be able to access these at
http://site1.local
http://site2.local
http://site3.local

So in my hosts file I have
127.0.0.1 site1.local
127.0.0.1 site2.local
127.0.0.1 site3.local

Then I have copied /etc/apache2/sites-available/default 3 times.

so now I have
/etc/apache2/sites-available/site1
/etc/apache2/sites-available/site2
/etc/apache2/sites-available/site3

These all look like (with appropriate sitex names)

<VirtualHost site1.local>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/site1
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/site1/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

In the terminal I then call

sudo a2ensite site1 site2 site3 && sudo /etc/init.d/apache2 reload

Which seems to work, except only one of the vhosts works at the same time (including default), What am I doing wrong?


When I run the reload command I get

  • Reloading web server config apache2
    apache2: Could not reliably determine the server's fully qualified domain name,
    using 127.0.1.1 for ServerName
    [Fri Apr 15 10:45:27 2011] [warn] NameVirtualHost *:80 has no VirtualHosts

3 Answers 3

2

Based on your hosts file, you map this line:

<VirtualHost site1.local>

to this:

<VirtualHost 127.0.0.1>

What you want is:

<VirtualHost *:80>
    ServerName site1.somesite.com

You may also need:

NameVirtualHost *:80

1
  • To elaborate on this, the reason that this is the case is that the bind address for the VirtualHost must match the NameVirtualHost statement, which is probably in your ports.conf file. See here for reference. Apr 15, 2011 at 1:32
2

I faced the same problem. After multiple trial and errors, I fixed the issue by adding NameVirtualHost *:80 to sites-available/default. And removing/not-adding the same line in any other files in sites-available/

I don't know why that worked though.

1

The error message of: "Could not reliably determine the server's fully qualified domain name..." is a quirky issue in the apache2 server and would not prevent or stop the apache2 server from locally "VirtualHost" ing your "ServerName". Read the link that Shane Madden gave as the solution is in there. The other "warn" message of: "NameVirtualHost *:80 has no VirtualHosts" will prevent you from having success.

Problem 1: The solution to the FQDN is simple and the two solutions seems to each have success for different users - so do both: Add the text string "ServerName localhost" (without quotes) to either (or both) of two files; the /etc/apache2/http.d.conf file, which is blank out of the box. And add it at the bottom of the /etc/apache2/apache2.conf file.

Problem 2: Reading the manual you will see examples on various setups for Apache2, but the one thing you really need to keep in mind is that the directive "NameVirtualHost" (which is located in /etc/apache2/ports.conf) needs to be EXACTLY the same as what you specify in the directive (located in the etc/apache2/sites-available/siteFile, where "siteFile" is your "site1", "site2" and "site3" in your example). Don't use boolean values in one and a static IP address or a static IP:Port in another. Once you understand the severity of that relationship then reading the manual and trying their setups will work.

Problem 3: The hidden problem: Knowing Problem 2, you now need to make sure it does not happen in your OTHER site files - namely, your default file. If the Default file has a VirtualHost *:80 and your site1 has a VirtualHost 127.0.0.1 AND your ports.conf has a NameVirtualHost 127.0.0.1 then the site1 and ports.conf are in harmony BUT the default is now no longer good and will cause the error.

Hang in there! It ain't easy...

You must log in to answer this question.

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