# Apache22 vhosts



## bsus (May 2, 2012)

Hi,

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


```
<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:

```
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


----------



## aunull (May 2, 2012)

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:

```
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*).


```
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


----------



## bsus (May 3, 2012)

Hi,

*Sor*ry but this doesn't work 

I changed the httpd-vhosts.conf like you wrote:

```
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


```
<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.



```
# /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.


----------



## bsus (May 3, 2012)

I now have changed the ServerName under httpd.conf:

```
ServerName 192.168.178.101:80
```

Now at lest the FQDN error is gone.


```
# /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?


----------



## bsus (May 3, 2012)

So I had to remove the 

```
Listen 80
```
line in httpd-vhosts.conf

Now only the 403 Forbidden error is available.


----------



## bsus (May 3, 2012)

I now found the source in the error_logs (should looked much more earlier there...):

```
[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 *chown*ed to www:www: No success.
I gave 755: No success.

Strange, let*'*s see what Google spits.


----------

