Bug 145000

Summary: Template for definig virtual hosts for Apache2 not completly correct.
Product: [openSUSE] SUSE Linux 10.1 Reporter: Nils-Olov Fransson <nof>
Component: NetworkAssignee: Peter Poeml <poeml>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Enhancement    
Priority: P5 - None CC: suse-beta
Version: Beta 2   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: Customer Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Nils-Olov Fransson 2006-01-23 22:18:53 UTC
I set up a couple of virtual hosts on my server and tried to follow the instructions given in the "/etc/apache2/vhosts.d/vhost.template". When it didn't work I read the documentation on vhosts on apache.orgs website and found the following.

1. There should be a NameVitualHost directive in the configuration file for each IP address used.
2. The order of the virtualhost sections for virtual hosts for the same IP address is important. If there is no name match the first virtual host is used.

This means that there should be only one .conf file for each IP address with all virtual hosts for that address specified. In order to use one .conf file for each virtual server you must name the .config files so they will be included in the correct order. This relies on that the files will be included in alphabetic order wich I don't know for sure.

I suggest that the comments in the template reflect some of the info that is in the README.QUICSTART file.
Comment 1 Michael Gross 2006-01-24 17:16:12 UTC
Thanks for reporting this!

I can fully acknowledge what Nils-Olov says here as I had the same problem on a 9.3 installation not long ago. Seems this is done this way since then.

I wanted to split up the virtual server config into one file per domain and failed because Apache only recognized the first VirtualHost and discarded the rest. Using one NameVirtualHost in each file did also not work, so finally I only could merge everything into one file and afterwards it worked perfectly. I could not find any hint how to do it with several files... looks like there is none?

If there really is no way to do this, this should be made clear in the example-configuration for users who like to configure their servers manually, like me ;) I would claim it is an enhancement nontheless...
Comment 2 Michael Gross 2006-01-24 17:18:15 UTC
For 10.1 anyway.
Comment 3 Christian Boltz 2006-01-24 20:35:33 UTC
(In reply to comment #1)
> I could not find any hint how to do it with several files... looks like there 
> is none?

This is may way to do this:

First, create a file  /etc/apache2/vhosts/aaaa_init_vhost.conf  with the following content (one line):
    NameVirtualHost *:80

This makes sure that all vHosts work. (You need more lines if you want to listen on more ports of course.)

Second, create a file  /etc/apache2/vhosts/aaa_default_vhost.conf and put the config of your _default_ vHost into it.

The conf files are included in alphabetical order, so don't use other filenames for the basic configuration.

Then create /etc/apache2/vhosts/*.conf for all the other vHosts you want to run - and do not let their names start with "aaa" ;-)
Comment 4 Peter Poeml 2006-01-25 12:51:36 UTC
There is a number of ways to do it... you can also put the
NameVirtualHost statements right next to the Listen statements into
/etc/apache2/listen.conf.
To include a certain default server configuration first, one can name it
with leading underscore, or 'aaa' or similar.

The readme in the package says:

o add virtual hosts:
  - edit /etc/apache2/listen.conf. It is a suitable place to add
    NameVirtualHost directives.
  - copy the commented template /etc/apache2/vhosts.d/vhost.template to
    /etc/apache2/vhosts.d/yourhost.conf
  - edit /etc/apache2/vhosts.d/yourhost.conf to suit your needs
  - alternative approach: simply append the NameVirtualHost directive and the
    <VirtualHost> container to your local configuration (httpd.conf.local --
    see above)
  - if in doubt about how apache interprets your vhost setup, always use
    httpd2 -S. If SSL is involved you will need to run httpd2 -S -DSSL instead --
    likewise for other needed defines.
  - the "default" server, which responds to requests not handled by other
    vhosts, is always the one which is defined first. If you want a dedicated
    "default" server for such requests, you need to put it first in the configuration.
    If the configuration is in multiple files, like /etc/apache2/vhosts.d/*.conf, then
    simply name the file _default.conf, or e.g. _192.168.0.1.conf if you do it per IP
    address.

Anything missing there?

I WOULD add a reference to the readme in the template now, if it didn't already contain it....

# See /usr/share/doc/packages/apache2/README.QUICKSTART for further hints 
# about virtual hosts.


But I have added a note about NameVirtualHost statements.

Any further suggestions?
Comment 5 Michael Gross 2006-01-25 13:07:11 UTC
Christian and Peter, thanks for the verbose answears. I think that would solve this - closing it as fixed. If you have another suggestion, Nils-Olov you can still add it here.