Apache22 vhosts

Hi,

I want to configure four different domains, each with its own web directory:

Code:
<VirtualHost 192.168.178.*:80>
    ServerAdmin support@example.com
    DocumentRoot "/usr/local/www/apache22/data"
    ServerName www.fritz.box
    ErrorLog "/var/log/www.fritz.box-error_log"
    CustomLog "/var/log/www.fritz.box-access_log" common
</VirtualHost>

<VirtualHost www.test.de:80>
    ServerAdmin support@test.de
    DocumentRoot "/usr/local/www/apache22/data/test"
    ServerName www.testcenter.com
    ErrorLog "/var/log/www.test.de-error_log"
    CustomLog "/var/log/www.test.de-access_log" common
</VirtualHost>

<VirtualHost cloud.example.com:80>
    ServerAdmin support@example.com
    DocumentRoot "/usr/local/www/apache22/data/example/owncloud"
    ServerName cloud.example.de 
    ErrorLog "/var/log/cloud.example.com-error_log"
    CustomLog "/var/log/cloud.example.com-access_log" common
</VirtualHost>

When I start apache:
Code:
Performing sanity check on apache22 configuration:
[Wed May 02 18:14:03 2012] [error] (EAI 4)Non-recoverable failure in name resolution: Could not resolve host name 192.168.178.* -- ignoring!
[Wed May 02 18:14:03 2012] [warn] VirtualHost www.test.de:80 overlaps with VirtualHost cloud.example.com:80, the first has precedence, perhaps you need a NameVirtualHost directive
[Wed May 02 18:14:03 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
Syntax OK
Stopping apache22.
Waiting for PIDS: 67861.
Performing sanity check on apache22 configuration:
[Wed May 02 18:14:03 2012] [error] (EAI 4)Non-recoverable failure in name resolution: Could not resolve host name 192.168.178.* -- ignoring!
[Wed May 02 18:14:03 2012] [warn] VirtualHost www.test.de:80 overlaps with VirtualHost cloud.example.com:80, the first has precedence, perhaps you need a NameVirtualHost directive
[Wed May 02 18:14:03 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
Syntax OK
Starting apache22.
[Wed May 02 18:14:03 2012] [error] (EAI 4)Non-recoverable failure in name resolution: Could not resolve host name 192.168.178.* -- ignoring!
[Wed May 02 18:14:03 2012] [warn] VirtualHost www.test.de:80 overlaps with VirtualHost cloud.example.com:80, the first has precedence, perhaps you need a NameVirtualHost directive
[Wed May 02 18:14:03 2012] [warn] NameVirtualHost *:80 has no VirtualHosts

Questions:
1. How do I add FQDN to /etc/hosts?
2. How do I set up NameVirtualHost directives?

Best Regards,
bsus
 
Hi,

Set the FQDN

Please note that you have to use a complete IP address, 192.168.178.* should not be used. I have used 192.168.178.100 as an example.

/etc/hosts:
Code:
192.168.178.100          [U]host-name[/U]

Fix up Virtual Hosts in Apache

I would use this instead, again you can't use 192.168.178.* and you need to use a complete IP address. I have used 192.168.178.100 as an example.com (You can check via ifconfig).

Code:
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin [email]support@example.com[/email]
    DocumentRoot "/usr/local/www/apache22/data"
    ServerName [url]www.fritz.box[/url]
    ServerAlias 192.168.178.100
    ErrorLog "/var/log/www.fritz.box-error_log"
    CustomLog "/var/log/www.fritz.box-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email]support@test.de[/email]
    DocumentRoot "/usr/local/www/apache22/data/test"
    ServerName [url]www.testcenter.com[/url]
    ServerAlias [url]www.test.de[/url]
    ErrorLog "/var/log/www.test.de-error_log"
    CustomLog "/var/log/www.test.de-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email]support@example.com[/email]
    DocumentRoot "/usr/local/www/apache22/data/example/owncloud"
    ServerName cloud.example.de 
    ErrorLog "/var/log/cloud.example.com-error_log"
    CustomLog "/var/log/cloud.example.com-access_log" common
</VirtualHost>

Start Apache

# apachectl start


It should work now :)
 
Hi,

Sorry but this doesn't work :(

I changed the httpd-vhosts.conf like you wrote:
Code:
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin support@example.com
    DocumentRoot "/usr/local/www/apache22/data"
    ServerName www.fritz.box
    ServerAlias 192.168.178.100
    ErrorLog "/var/log/www.fritz.box-error_log"
    CustomLog "/var/log/www.fritz.box-access_log" common
</VirtualHost>
This should only be available in the local network. That's why I used 192.168.178.*:89

Code:
<VirtualHost *:80>
    ServerAdmin support@test.de
    DocumentRoot "/usr/local/www/apache22/data/test"
    ServerName www.testcenter.com
    ServerAlias www.test.de
    ErrorLog "/var/log/www.test.de-error_log"
    CustomLog "/var/log/www.test.de-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin support@example.com
    DocumentRoot "/usr/local/www/apache22/data/example/owncloud"
    ServerName cloud.example.de 
    ErrorLog "/var/log/cloud.example.com-error_log"
    CustomLog "/var/log/cloud.example.com-access_log" common
</VirtualHost>
These both should handle different domains.


Code:
# /usr/local/etc/rc.d/apache22 restart
Performing sanity check on apache22 configuration:
httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.178.101 for ServerName
Syntax OK
Stopping apache22.
Waiting for PIDS: 67923.
Performing sanity check on apache22 configuration:
httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.178.101 for ServerName
Syntax OK
Starting apache22.
httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.178.101 for ServerName

Furthermore I get a HTTP 403 Forbidden when accessing the IP/domain of the server.
 
I now have changed the ServerName under httpd.conf:
Code:
ServerName 192.168.178.101:80

Now at lest the FQDN error is gone.

Code:
# /usr/local/etc/rc.d/apache22 start
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache22.
(48)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
/usr/local/etc/rc.d/apache22: WARNING: failed to start apache22

This is now the additional error message.
Any idea why this is so and how I can fix this?
 
So I had to remove the
Code:
Listen 80
line in httpd-vhosts.conf

Now only the 403 Forbidden error is available.
 
I now found the source in the error_logs (should looked much more earlier there...):
Code:
[Thu May 03 14:05:25 2012] [crit] [client 87.187.41.2] (13)Permission denied: /.htaccess
 pcfg_openfile: unable to check htaccess file, ensure it is readable

I Googled a bit and found out that this means that apache can't access the directories properly.
So I chowned to www:www: No success.
I gave 755: No success.

Strange, let's see what Google spits.
 
Back
Top