Mailinglist Archive: opensuse (714 mails)

< Previous Next >
Re: [opensuse] (Strange) Apache Virtual Host Behaviour
You could also configure /etc/apache2/default-server.conf, which is always
loaded first ;-)

Johannes

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

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>
</VirtualHost>


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

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.


--
Johannes Weberhofer
Weberhofer GmbH, Austria, Vienna
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References