Mailinglist Archive: opensuse (714 mails)

< Previous Next >
Re: [opensuse] (Strange) Apache Virtual Host Behaviour
Well, really the technically most correct way seems to be:

httpd.conf loads /etc/apache2/sysconfig.d/include.conf just before the vhosts.d/*.conf

So just as the comment in /etc/sysconfig/apache2 sates:

# Here you can name files, separated by spaces, that should be Include'd from.
# httpd.conf..
# This allows you to add e.g. VirtualHost statements without touching.
# /etc/apache2/httpd.conf itself, which makes upgrading easier..

The good:
* not editing stock files = portable at least among suse hosts and upgrade-safe
* custom config in separate file = portable and upgrade-safe

The bad:
* suse-specific sysconfig is a suse customization of apache, not a normal part of apache you can expect to find on any apache host = not portable
* you must specify a file that is essentially a vhost.d/*.conf file, but it should live anywhere but in vhosts.d or if in there it should be named anything but *.conf, in order to keep it from getting read twice, or just let it get read twice.
* It's doing 2 or more things to save from having to do 1 thing = bad math

On a given new box, you'd have to manually edit /etc/sysconfig/apache2 which is no more or less work than editing httpd.conf or some other file.

The one justification depends on if you actually use the provided feature smartly. IF you use the sysconfig file, and IF you use that feature to specify all files that live in some separate place that is brainless for you to back up, that is valuable. You could include files that that not only specify the default vhost config first, but you could include "include" directives that include vhost *.conf files from some directory of your own and not have any in /etc/apache2/vhosts.d/.
Then your entire setup would be brainless to backup and/or copy to another host just by grabbing /etc/sysconfig/apache2 and the single directory tree where you have all your *.conf files and htdocs and cgi-bin etc. No chance of missing something, no chance of incompatible insertion into new host.


On 10/11/2011 10:45 AM, Johannes Weberhofer wrote:
You could also configure /etc/apache2/default-server.conf, which is
always loaded first ;-)


Am 11.10.11 15:22, schrieb CHONG Yu Meng:
Thanks Brian!

I got the whole thing sorted out by putting all the Virtual Host
declarations inside one file instead of splitting them into separate
files. This way, I always know which is the "first" or "default" Virtual
Host. Not an elegant solution, but it works.

After some more Googling, I realized that OpenSUSE's Apache actually
looks at the filename and sorts it alphabetically, so your suggested
practice of naming the first Virtual Host as "_default.conf" would work.

There are still a few odd quirks in OpenSUSE's Apache, but I think I
have a handle on this now.

Thanks and Best Regards,
pascal chong

----- Original Message -----
From: "Brian K. White"<brian@xxxxxxxxx>
To: opensuse@xxxxxxxxxxxx
Sent: Monday, October 10, 2011 11:25:24 PM
Subject: Re: [opensuse] (Strange) Apache Virtual Host Behaviour

On 10/10/2011 10:23 AM, CHONG Yu Meng wrote:
Hi all,

So, I setup Apache on my OpenSUSE 11.4 server at home, wanting to
experiment with several php and perl apps (hence the Virtual Hosting
config), when I found some strange behaviour with Virtual Hosting.

I have a default configuration in Apache which I can access using
hostorig.domain.tld (not the real name of course). I create a Virtual
Host, host1.domain.tld and put an index.html inside. It works, so far so

Ok, now, I add another Virtual Host, host2.domain.tld, and things start
to get strange. When I open a browser and go to "http://hostorig";, I get
"http://host1"; instead. "http://host1"; still points to the right place,
and "http://host2"; point to the right place too.

A bit of Googling around leads me to a site that says that the order of
the<VirtualHost> stanzas is significant. If Apache does not understand
which Virtual Host the user is requesting, it will default to the first
<VirtualHost> declaration.

Now, in OpenSUSE, the order of the Virtual Hosts is not so clear because
they are all contained in separate .conf files inside
/etc/apache2/vhost.d. If I wanted one of the Virtual Hosts here to be
the "first" Virtual Host declared, what do I do?

Since this is a home setup, it's not really that important, but it is
annoying me like crazy. If anyone here can give me any information on
why all this is happening and how I can setup a Virtual Host that Apache
will "default" to when it doesn't understand the destination (or just
setup Virtual Hosts better), please help!

Thanks in Advance,
pascal chong

I have this in /etc/apache2/httpd.conf :

# define a default do-nothing "vhost" before including any possible
config files
# so that defaults will end up coming from the main config files instead
# of requiring a vhost.conf with a special filename that will get read
# before others
<VirtualHost *:80>

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

The last line was already there and I inserted the comments and
virtualhost above.

I think if you put the same two lines into a file named like
/etc/apache2/vhosts.d/_default.conf or 0_default.conf etc it will
probably always be read first but I didn't want to rely on that or do
the necessary testing or code-looking to make sure because it was much
easier and utterly certain to do this.

It's slightly bad for us to edit httpd.conf directly/manually, but it's
even worse for apache or suse to fail to define the behavior of "Include
/etc/apache2/vhosts.d/*.conf" when the order does matter.

Generally, in any app, unless explicitly documented, you can not count
on filesystem globbing patterns like that to produce results in any
particular order. Not alphanumeric, not create or modify time, not inode
number etc... Some programs do some internal sorting. For example "ls"
of course has several different sorting options. But "ls" is doing that
itself, the filesystem and kernel has no particular order, at least not
that a human ever finds useful. So, short of explicit documentation, or
testing, or looking at the code, the only sure way to get a particular
order is to list it in httpd.conf explicitly in the order you need.

Also this way I don't have to care what any vhosts *.conf files are
named. One could come along later named ____.conf and it won't break

Maybe there is a real defined way, like maybe a special name like
".conf" is guaranteed to always be first no matter what. I don't know.
But if somewhere that's documented, that would be the better way to go
instead of editing httpd.conf.

To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >