You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by billy noah <bi...@gmail.com> on 2018/06/23 15:22:15 UTC

[users@httpd] matches when ServerName directive is omitted

I am in the process of migrating some sites from a server running Apache
2.4.7 to a new installation (Ubuntu 18) running Apache 2.4.29 and running
into some issues with VirtualHost matching.

On my old server I have a config like this:

<VirtualHost 12.34.56.78:80>
    ServerAlias *.dev.example.com
    VirtualDocumentRoot /var/www/dev/%1
</VirtualHost>

<VirtualHost 12.34.56.78:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example/
</VirtualHost>

As you can see, the ServerName directive is intentionally absent from the
first host which uses a VirtualDocumentRoot to serve directories based on
the subdomain. This has been working fine on the old server.

In my new environment everything worked fine at first, but today (no
updates, nothing changed), oddly things changed. For some reason apache
started matching example.com to the first vhost and after some amount of
debugging I have determined that this is due to the lack of ServerName
directive. When I add one - anything really - the problem goes away. So to
be clear, a working config now looks like this:

<VirtualHost 12.34.56.78:80>
    ServerName anything.dev.example.com
    ServerAlias *.dev.example.com
    VirtualDocumentRoot /var/www/dev/%1
</VirtualHost>

<VirtualHost 12.34.56.78:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example/
</VirtualHost>

The apache docs have this to say about omitting the ServerName directive:

If you omit the ServerName directive from any name-based virtual host, the
server will default to a fully qualified domain name (FQDN) derived from
the system hostname.

My system hostname is something like servername.example.com - which
shouldn't match example.com.

My question:

Has there been some change in Apache's behaviour with this newer version
that would break my previous configuration? I'm looking for an explanation
about why this worked fine in the old environment and now suddenly does
not. I'm also looking for any explanation at all about why Apache would be
matching my first vhost when ServerName is absent.

Re: [users@httpd] matches when ServerName directive is omitted

Posted by Daniel Gruno <hu...@apache.org>.
On 06/23/2018 10:34 AM, billy noah wrote:
> Thanks Eric, the rdns almost certainly /did /change so that could be the 
> culprit.  Do you have a definitive answer or a way to determine how 
> apache decides what "ServerName" should be when the directive is 
> absent?  

 From the documentation:

     If no ServerName is specified, the server attempts to deduce the
     client visible hostname by first asking the operating system for the
     system hostname, and if that fails, performing a reverse lookup on
     an IP address present on the system.

so basically it will do a gethostname() call first, falling back to a 
reverse lookup.

With regards,
Daniel.

I'll stick with the policy of using something (even nonsense as
> you suggested) in the future, but I'm curious to understand the precise 
> mechanics of what is happening here.  Is there some way to get a log of 
> apache's decision making factors when determining which vhost to serve?
> 
> On Sat, Jun 23, 2018 at 11:28 AM, Eric Covener <covener@gmail.com 
> <ma...@gmail.com>> wrote:
> 
>     On Sat, Jun 23, 2018 at 11:22 AM billy noah <billynoah@gmail.com
>     <ma...@gmail.com>> wrote:
>     >
>     > I am in the process of migrating some sites from a server running Apache 2.4.7 to a new installation (Ubuntu 18) running Apache 2.4.29 and running into some issues with VirtualHost matching.
>     >
>     > On my old server I have a config like this:
>     >
>     > <VirtualHost 12.34.56.78:80 <http://12.34.56.78:80>>
>     >     ServerAlias *.dev.example.com <http://dev.example.com>
>     >     VirtualDocumentRoot /var/www/dev/%1
>     > </VirtualHost>
>     >
>     > <VirtualHost 12.34.56.78:80 <http://12.34.56.78:80>>
>     >     ServerName example.com <http://example.com>
>     >     ServerAlias www.example.com <http://www.example.com>
>     >     DocumentRoot /var/www/example/
>     > </VirtualHost>
>     >
>     > As you can see, the ServerName directive is intentionally absent from the first host which uses a VirtualDocumentRoot to serve directories based on the subdomain. This has been working fine on the old server.
> 
>     It's unwise. You should at least pick some nonsense name.
> 
>     >
>     > In my new environment everything worked fine at first, but today (no updates, nothing changed), oddly things changed. For some reason apache started matching example.com <http://example.com> to the first vhost and after some
>     amount of debugging I have determined that this is due to the lack
>     of ServerName directive. When I add one - anything really - the
>     problem goes away. So to be clear, a working config now looks like this:
>     >
>     > <VirtualHost 12.34.56.78:80 <http://12.34.56.78:80>>
>     >     ServerName anything.dev.example.com <http://anything.dev.example.com>
>     >     ServerAlias *.dev.example.com <http://dev.example.com>
>     >     VirtualDocumentRoot /var/www/dev/%1
>     > </VirtualHost>
>     >
>     > <VirtualHost 12.34.56.78:80 <http://12.34.56.78:80>>
>     >     ServerName example.com <http://example.com>
>     >     ServerAlias www.example.com <http://www.example.com>
>     >     DocumentRoot /var/www/example/
>     > </VirtualHost>
> 
>     Perhaps the reverse DNS of your IP address changed?  I don't think
>     it's directly the "system hostname".
> 
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>     <ma...@httpd.apache.org>
>     For additional commands, e-mail: users-help@httpd.apache.org
>     <ma...@httpd.apache.org>
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] matches when ServerName directive is omitted

Posted by billy noah <bi...@gmail.com>.
Thanks Eric, the rdns almost certainly *did *change so that could be the
culprit.  Do you have a definitive answer or a way to determine how apache
decides what "ServerName" should be when the directive is absent?  I'll
stick with the policy of using something (even nonsense as you suggested)
in the future, but I'm curious to understand the precise mechanics of what
is happening here.  Is there some way to get a log of apache's decision
making factors when determining which vhost to serve?

On Sat, Jun 23, 2018 at 11:28 AM, Eric Covener <co...@gmail.com> wrote:

> On Sat, Jun 23, 2018 at 11:22 AM billy noah <bi...@gmail.com> wrote:
> >
> > I am in the process of migrating some sites from a server running Apache
> 2.4.7 to a new installation (Ubuntu 18) running Apache 2.4.29 and running
> into some issues with VirtualHost matching.
> >
> > On my old server I have a config like this:
> >
> > <VirtualHost 12.34.56.78:80>
> >     ServerAlias *.dev.example.com
> >     VirtualDocumentRoot /var/www/dev/%1
> > </VirtualHost>
> >
> > <VirtualHost 12.34.56.78:80>
> >     ServerName example.com
> >     ServerAlias www.example.com
> >     DocumentRoot /var/www/example/
> > </VirtualHost>
> >
> > As you can see, the ServerName directive is intentionally absent from
> the first host which uses a VirtualDocumentRoot to serve directories based
> on the subdomain. This has been working fine on the old server.
>
> It's unwise. You should at least pick some nonsense name.
>
> >
> > In my new environment everything worked fine at first, but today (no
> updates, nothing changed), oddly things changed. For some reason apache
> started matching example.com to the first vhost and after some amount of
> debugging I have determined that this is due to the lack of ServerName
> directive. When I add one - anything really - the problem goes away. So to
> be clear, a working config now looks like this:
> >
> > <VirtualHost 12.34.56.78:80>
> >     ServerName anything.dev.example.com
> >     ServerAlias *.dev.example.com
> >     VirtualDocumentRoot /var/www/dev/%1
> > </VirtualHost>
> >
> > <VirtualHost 12.34.56.78:80>
> >     ServerName example.com
> >     ServerAlias www.example.com
> >     DocumentRoot /var/www/example/
> > </VirtualHost>
>
> Perhaps the reverse DNS of your IP address changed?  I don't think
> it's directly the "system hostname".
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] matches when ServerName directive is omitted

Posted by Eric Covener <co...@gmail.com>.
On Sat, Jun 23, 2018 at 11:22 AM billy noah <bi...@gmail.com> wrote:
>
> I am in the process of migrating some sites from a server running Apache 2.4.7 to a new installation (Ubuntu 18) running Apache 2.4.29 and running into some issues with VirtualHost matching.
>
> On my old server I have a config like this:
>
> <VirtualHost 12.34.56.78:80>
>     ServerAlias *.dev.example.com
>     VirtualDocumentRoot /var/www/dev/%1
> </VirtualHost>
>
> <VirtualHost 12.34.56.78:80>
>     ServerName example.com
>     ServerAlias www.example.com
>     DocumentRoot /var/www/example/
> </VirtualHost>
>
> As you can see, the ServerName directive is intentionally absent from the first host which uses a VirtualDocumentRoot to serve directories based on the subdomain. This has been working fine on the old server.

It's unwise. You should at least pick some nonsense name.

>
> In my new environment everything worked fine at first, but today (no updates, nothing changed), oddly things changed. For some reason apache started matching example.com to the first vhost and after some amount of debugging I have determined that this is due to the lack of ServerName directive. When I add one - anything really - the problem goes away. So to be clear, a working config now looks like this:
>
> <VirtualHost 12.34.56.78:80>
>     ServerName anything.dev.example.com
>     ServerAlias *.dev.example.com
>     VirtualDocumentRoot /var/www/dev/%1
> </VirtualHost>
>
> <VirtualHost 12.34.56.78:80>
>     ServerName example.com
>     ServerAlias www.example.com
>     DocumentRoot /var/www/example/
> </VirtualHost>

Perhaps the reverse DNS of your IP address changed?  I don't think
it's directly the "system hostname".

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org