4

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?

2 Answers2

6

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>
Linker3000
  • 28,240
1

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.