Virtual Hosts nightmare...

Hi…

I’m trying to use the Apache included with SLES (close enough to OpenSuse I hope) to create a virtual host environment.

My default host, and default SSL virtual host, both work fine. My problem is when I add an additional vhost by editing the vhost.template and saving it as a .conf file I lose all of my sites. And adding a virtual host via Yast doesn’t work either.

Is there something unique about the SuSE setup that I’m not seeing?

For reference, my named vhost.conf file looks like this:

<VirtualHost my.domain.org:80>

 DocumentRoot /srv/www/my-htdocs/

 ServerName my.domain.org
 ServerAdmin jcochran@mydomain.org
 <Directory /srv/www/my-htdocs/>

  AllowOverride None

  Order allow,deny

  Allow from all

 </Directory>

</VirtualHost>

<VirtualHost www.domain.org:80>
 DocumentRoot /srv/www/htdocs/
 ServerName my.domain.org
 ServerAdmin jcochran@otherdomain.org
 <Directory /srv/www/htdocs/>
  AllowOverride None
  Order allow,deny
  Allow from all
 </Directory>

</VirtualHost>

I’ve tried setting this up in various combinations, leaving out the default domain, since it seems to be included in the default-server.conf file.

Nothing seems to work.

Any insight would be much appreciated.

Not sure about sles but in opensuse i have my entries in /etc/apache2/default-server.conf

Geoff

Hi
Try change the <VirtualHost my.domain.org:80> to <VirtualHost !your IP here!:80> to use IP base virtual hosting.
ServerName directive should have different names for each virtual host declaration, and (I’m not shure about this) each vhost should point to different directory.
I.E.

<VirtualHost 10.1.1.100:80>
ServerAdmin admin@sth.org
DocumentRoot /srv/www/sth.org
ServerName www.sth.org                                  
</VirtualHost>                               


<VirtualHost 10.1.1.100:80>
ServerAdmin admin@sthdiff.org    
DocumentRoot /srv/www/sthdiff.org 
ServerName www.sthdiff.org                            
</VirtualHost> 

I hope this helps.

I’m actually running the hosts on the same IP, trying to do vhosts by name (which is possible, according to apache documentation).

Please post the output of:

/usr/sbin/httpd2-prefork -S

If domain name is correctly resolved to IP, you can use name instead of IP number, but it’s not the point. Point is your ServerName directive set to same hostname, and VirtualHost declarations are set for different hosts. The VirtualHost should contain the real host IP or name, and ServerName within VirtualHost tells Apache about virtual domain.

Both hostnames that I’m trying to virtually host point to the same IP, and they both (now) go to the same site.

I will do so tonight once I try the virtual hosts setup again. I’ve gone back to the one host for the business day.

Here it is, with domains and IPs changed to protect the innocent. :slight_smile:


[Fri Nov 07 23:51:06 2008] [warn] VirtualHost my.domain.org:80 overlaps with VirtualHost [Domain.org](http://www.domain.org:80), the first has precedence, perhaps you need a NameVirtualHost directive
[Fri Nov 07 23:51:06 2008] [warn] NameVirtualHost *:0 has no VirtualHosts
VirtualHost configuration:
205.xxx.xxx.xxx:80        my.domain.org (/etc/apache2/vhosts.d/yast2_vhosts.conf:1)
Syntax OK

When it’s in this state, none of our sites are accessable.

You should uncomment the line:

NameVirtualHost *:80

in /etc/apache2/listen.conf to activate virtual hosting. Any request that doesn’t match a virtualhost name maps to the first virtualhost read in by Apache. Therefore I normally put the default virtualhost spec in 000default.conf in /etc/apache2/vhosts.d. (It’s good practice to put one virtualhost per .conf file in that directory.) And I often make this default virtualhost serve very little, not even a front page, to feed the web vermin that just go scanning IP addresses for web apps with security holes.

Sometimes people mistakenly think it’s the line

<VirtualHost my.domain.org:80>

that tells Apache what the vhost names are. It is not. It is in fact the line:

ServerName my.domain.org

plus any ServerAlias lines. That VirtualHost line should be changed to

<VirtualHost *:80>

so that your virtualhost is active on all interfaces (including any secondary IP addresses, VPN addresses) as this is the normal case. Only when you want to restrict the virtualhost to certain addresses do you restrict it.

Alright, I see the line in listen.conf, and thanks for all of your help. :slight_smile:

I’m going to give this a try tonight and see if it works. I’ll report back either way.

Thanks again!

And it seems like it totally worked. Thanks again for all of your help.