Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have setup an Apache 2 virtual host by this method.

under /etc/apache2/sites-available I've create a dummy_site_1.conf

dummy_site_1.conf

<VirtualHost local.dummy_site_1:80>
    ServerName local.dummy_site_1
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/dummy_site_1
    ErrorLog /var/log/apache2/dummy_site_1__error.log
    TransferLog /var/log/apache2/dummy_site_1__access.log
    <Directory /var/www/dummy_site_1>
        AllowOverride Options Limit None
        Options -Indexes FollowSymLinks
    Order deny,allow
    Allow from all
    </Directory>
    DirectoryIndex index.php
    #DISABLE HTTP TRACE
    #RewriteEngine On
    #RewriteCond %{REQUEST_METHOD} ^TRACE
    #RewriteRule .* - [F]
</VirtualHost>

I also added this line the the httpd.conf:

ServerName local.dummy_site_1

Now all is working with this setup, I type local.dummy_site_1 in the URL and I can see my site.

The problem is when I try to add another site config dummy_site_2.conf and create about the same settings

dummy_site_2.conf

<VirtualHost local.dummy_site_2:80>
    ServerName local.dummy_site_2
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/dummy_site_2
    ErrorLog /var/log/apache2/dummy_site_2__error.log
    TransferLog /var/log/apache2/dummy_site_2__access.log
    <Directory /var/www/dummy_site_2>
        AllowOverride Options Limit None
        Options -Indexes FollowSymLinks
    Order deny,allow
    Allow from all
    </Directory>
    DirectoryIndex index.php
    #DISABLE HTTP TRACE
    #RewriteEngine On
    #RewriteCond %{REQUEST_METHOD} ^TRACE
    #RewriteRule .* - [F]
</VirtualHost>

I also added this line the the httpd.conf:

ServerName local.dummy_site_2

I get this error:

user@host:/etc/apache2$ sudo /etc/init.d/apache2 restart
 * Restarting web server apache2                                                                                                                                                                     [Wed Sep 15 14:00:43 2010] [error] (EAI 5)No address associated with hostname: Could not resolve host name local.dummy_site_2 -- ignoring!
 ... waiting [Wed Sep 15 14:00:44 2010] [error] (EAI 5)No address associated with hostname: Could not resolve host name local.dummy_site_2 -- ignoring!

Why? am I configuring this wrong?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You don't need 'ServerName local.dummy_site_2' in httpd.conf so take that out, but add this instead:

NameVirtualHost ip-address-of-server:80

eg: NameVirtualHost 192.168.1.10:80

Once you have made the change you will need to restart Apache.

If things still do not work as expected, add a line to each of your virtualhost conf files below the servername lines so they look like this:

ServerName local.dummy_site_1
ServerAlias *.local.dummy_site_1 local.dummy_site_1

and

ServerName local.dummy_site_2
ServerAlias *.local.dummy_site_2 local.dummy_site_2

Again, restart Apache to check out the changes.

EDIT: Silly me - just spotted the other bit of the problem - ALL of your VirtualHost declarations should use the IP address of the virtual server - eg:

<VirtualHost 192.168.1.10:80>
share|improve this answer
    
Thanks for the help, I did step on and got an error. Did step 2 and same error as well as the original error: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName –  Phill Pafford Sep 15 '10 at 18:46
    
I'm using a static IP if that matters –  Phill Pafford Sep 15 '10 at 18:47
    
Hmm - not sure about the error if you put the NameVirtualHost line in - I just checked one of our servers that is hosting 8 virtual sites and the syntax checks out. The message about the fully qualified domain name should not stop things working, but check that /etc/hosts has a line for 127.0.0.1 listing the names for your server eg: mine is 127.0.0.1 rusty.localdomain rusty localhost.localdomain localhost –  Linker3000 Sep 15 '10 at 18:57
    
See my edit to my original reply - just spotted the final bit of the jigsaw! –  Linker3000 Sep 15 '10 at 19:11
    
hmm, that gave the same error as well, also when I hit the first site it comes up with the It works message from Apache instead –  Phill Pafford Sep 15 '10 at 19:59

Actually, you can remove the IP address and or site name altogether.

example:

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
ServerAdmin emailaddress@domain.tld
DocumentRoot "/path/to/vhost/documents"
ServerName servername.domain.tld
ServerAlias serveralias.domain.tld
ErrorLog "/path/to/logfiles/servername.domain.tld-error.log"
CustomLog "/path/to/logfiles/servername.domain.tld-access.log" common
<Directory "/path/to/vhost/documents">
allow from all
Option +Indexes
</Directory>
</VirtualHost>

<VirtualHost *:443>
ServerAdmin emailaddress@domain.tld
DocumentRoot "/path/to/vhost/documents"
ServerName servername.domain.tld
ServerAlias serveralias.domain.tld
SSLEngine On
SSLCertificateFile /path/to/certificate/file.cert
SSLCertificateKeyFile /path/to/certificate/file.key
ErrorLog "/path/to/logfiles/servername.domain.tld-error.log"
CustomLog "/path/to/logfiles/servername.domain.tld-access.log" common
<Directory "/path/to/vhost/documents">
allow from all
Option +Indexes
</Directory>
</VirtualHost>

(Now, lets do an example of vhost combined with mod_proxy; ip=numeric-octet, below)

<VirtualHost *:80>
ProxyPreserveHost Off
ProxyPass / http://ip.ip.ip.ip/
ProxyPassReverse / http://ip.ip.ip.ip/
ServerName servername.domain.tld
</VirtualHost>

Basically, so long as your DNS info matches up with the vhosts you configure, then it should all work.

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.