# Problems with virtualhost

## zeuz

Hi!

I'm having problems setting up virtualhost.

I've got two domains which points on my server dyndns host.

They both worked, but after a reboot, the second domain points to default one.

What am I doing wrong?

This is my 00_default_vhost.conf:

*see below*Last edited by zeuz on Mon Feb 19, 2007 10:06 pm; edited 1 time in total

----------

## thecooptoo

take the comments out of your config file post  

do 

grep ^[A-Za-z0-9] /etc/apache...../../vhosts.conf

and then replace whats there with this 

it will be much easier to see whats going on

----------

## zeuz

Sorry about that. I've only added the second virtual host.

```

NameVirtualHost *:80

<IfDefine DEFAULT_VHOST>

<VirtualHost *:80>

    DocumentRoot "/var/www/localhost/htdocs"

    <Directory "/var/www/localhost/htdocs">

        Options Indexes FollowSymLinks

        AllowOverride None

        Order allow,deny

        Allow from all

    </Directory>

    <IfModule peruser.c>

        ServerEnvironment apache apache

        MinSpareProcessors 4

        MaxProcessors 20

    </IfModule>

    <IfModule itk.c>

        AssignUserID apache apache

        MaxClientsVHost 50

    </IfModule>

</VirtualHost>

</IfDefine>

<VirtualHost *:80>

    ServerAdmin webmaster@domain.se

    DocumentRoot /var/www/domain.se/htdocs

    ServerName domain.se

    ErrorLog /var/log/apache2/domain.se-error_log

    CustomLog /var/log/apache2/domain.se-access_log common

</VirtualHost> 
```

----------

## thecooptoo

try commenting out the IFDefine directives, or move the closing one to the very end  ( ie  including both vhosts definitions ) and then restart apache

----------

## zeuz

When I comment out the <ifdefine>-lines none of the domains work. If i put hte ifdefine bracket around both of them it still behaves as before, both domains points to the default one.Last edited by zeuz on Fri Feb 23, 2007 10:51 pm; edited 1 time in total

----------

## thecooptoo

like this 

```
NameVirtualHost *:80

<IfDefine DEFAULT_VHOST>

<VirtualHost *:80>

    DocumentRoot "/var/www/localhost/htdocs"

    <Directory "/var/www/localhost/htdocs">

        Options Indexes FollowSymLinks

        AllowOverride None

        Order allow,deny

        Allow from all

    </Directory>

    <IfModule peruser.c>

        ServerEnvironment apache apache

        MinSpareProcessors 4

        MaxProcessors 20

    </IfModule>

    <IfModule itk.c>

        AssignUserID apache apache

        MaxClientsVHost 50

    </IfModule>

</VirtualHost>

<VirtualHost *:80>

    ServerAdmin webmaster@domain.se

    DocumentRoot /var/www/domain.se/htdocs

    ServerName domain.se

    ErrorLog /var/log/apache2/domain.se-error_log

    CustomLog /var/log/apache2/domain.se-access_log common

</VirtualHost>

</IfDefine>

```

----------

## zeuz

Just tried that and I also double checked the values, still doesn't work.  :Sad:  One crazy thing I noticed is that the second domain returns another ip-address when I ping it. How could that be when it points on my server?

----------

## thecooptoo

whats in the log files when you access the pages ?

----------

## zeuz

Nothing except that the default access_log get hits from both domains.  I think i've found the problem though. I'm having trouble pointing the domains with cname to my dyndns host. I've pointed them directly to my ip-address. Just have to wait and see if that changes anything.

----------

## thecooptoo

put your domain names in a clients /etc/hosts and point them to your server and see what happens

----------

## zeuz

Didn't think of that, thanks. I'm still having the same problem though. I've tried with ifdefine on both and only on the first one. No errors in the log files either.  :Sad: 

----------

## zeuz

Does anyone have any ideas on what I can try to get this to work?

----------

## thecooptoo

does it work using a client /etc/hosts to point he domain name to your server ?

whats the output of 

 cat /etc/apache2/httpd.conf |grep vhosts

have you allowed access to  each document root 

eg something like  in httpd.conf

 *Quote:*   

> <Directory /var/www/localhost/htdocs>
> 
>   Order allow,deny
> 
>     Allow from all
> ...

 

----------

## zeuz

It doesn't work by adding the domains to /etc/host or in windows host-file on another machine.

 cat /etc/apache2/httpd.conf |grep vhosts:

```

# Please see vhosts.d/00_default_vhost.conf for the default virtual host.

Include /etc/apache2/vhosts.d/*.conf

```

Added the directory allowance on the second vhost:

```

<VirtualHost *:80>

    ServerAdmin webmaster@domain.se

    DocumentRoot /var/www/domain.se/htdocs

    ServerName domain.se

    ErrorLog /var/log/apache2/domain.se-error_log

    CustomLog /var/log/apache2/domain.se-access_log common

    <Directory "/var/www/domain.se/htdocs">

        Options -Indexes FollowSymLinks

        AllowOverride None

        Order allow,deny

        Allow from all

    </Directory>

</VirtualHost>
```

Really nice of you to help me thecooptoo.  :Smile: 

----------

## thecooptoo

whats /etc/conf.d/apache2 and do you have vhosts in your USE flags 

from the client can you ping  your servernames and get the correct Ip address back ?

to check its not a permissions problem find , in /etc/httpd.conf  the first Directive 

<Directory />

and then change its contents to Allow from All 

and then see what happens 

if you get your web pages served correctly then its  permissions problem 

then CHANGE IT BACK  and we can sort it out from there

----------

## zeuz

/etc/conf.d/apache2:

```
APACHE2_OPTS="-D DEFAULT_VHOST -D PHP5"
```

I didn't have vhost in my USE flags, is it here the problem lies?

Allow from All didn't work either.

I really appreciate that you help me on this.  :Smile: 

Edit: Reemerged apache with the vhost flag and restarted apache. Didn't work either.  :Sad: 

Edit2: This is crazy. I added a subdomain to my default domain and copied the vhost code for my second domain and it works?

----------

## zeuz

I'm still having problems with my second domain. thecooptoo has been trying to help without any luck yet. The strange thing is that i've added two subdomains (subdomain to my default domain) and they work with the lines used for my second domain.

Any help is appreciated , thanks.

----------

## zeuz

Okay, now my second domain works if I don't use www, why is that? Solved it by adding yet another vhost with ServerName set to www.domain2.se.

----------

## thecooptoo

sorry -been away and tied up - are you fixed yet  ?

----------

## zeuz

Yes, everything works now.  :Smile:  I have to set up two virtual hosts for the standalone domain though. One for domain.se and the other one for www.domain.se. Anyway, it works so i'm happy.  :Smile:  Thanks for your help.

----------

