You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Matt Price <ma...@utoronto.ca> on 2010/10/23 14:10:10 UTC

[users@httpd] mixing dynamic and static virtual host definitions

  Hello,

I'm running apache 2.2.16 on a recent Ubuntu Maverick install (ubuntu 
package version 2.2.16-1ubuntu3).  This is on a standalone box with just 
a few small websites on it.  These sites mostly run wordpress 
installations, which I manage with the dynamic stanzas suggested by the 
debian package maintainers.  These look like this:
-------------------
<Directory />
             Options FollowSymLinks
             AllowOverride All
</Directory>

<VirtualHost *:80>
         UseCanonicalName    Off
         VirtualDocumentRoot /var/www/%0
         Options All
         RewriteEngine On
         RewriteRule ^/wp-uploads/(.*)$ /var/www/wp-uploads/%{HTTP_HOST}/$1
</VirtualHost>

------------------------------

These work completely unproblematically. I recently added another site, 
though, which is managed by drupal.  I would like to access this site in 
the following manner:

<VirtualHost *:80>
              VirtualDocumentRoot /home/drupal-commons/drupal_commons
              ServerName tdhc.digitalcommons.ca
</VirtualHost>

My expectation is that adding this stanza above the <VirtualHost> 
directive I show above should direct all traffic on 
tdhc.digitalcommons.ca to /home/drupal-commons/drupal_commons/, and 
allow other traffic to proceed to the wordpress sites in /var/www/*.  
However, I get the following behaviour:

1) if the new stanza is placed above the old one, then ALL traffic 
arriving at this server is directed to  /home/drupal-commons/drupal_commons.
2) if the new stanza goes below the old, it is ignored entirely (this is 
what I expected).

Can someone tell me what I'm doing wrong and how I should fix it?

Thanks so much for your help!  Best,
Matt

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mixing dynamic and static virtual host definitions

Posted by Rich Bowen <rb...@rcbowen.com>.
On Oct 25, 2010, at 2:12 PM, Matt Price wrote:

> On 10-10-25 12:23 PM, Rich Bowen wrote:
>>
>> On Oct 25, 2010, at 12:07 PM, Matt Price wrote:
>> The solution is to put a ServerName (and possibly one or more  
>> ServerAlias directives) in the second VirtualHost.
>>
> thank you.  Things seem to work now -- though I confess to being a  
> bit surprised that ServerName * will work in this instance.  And it  
> would rbe nice to be able to specify a root location for requests  
> without a HOST header.  But that will doubtless come.  Thanks so much!


The reason that ServerName * doesn't work is that the value of  
ServerName is used to generate self-referential URLs, for example when  
an internal redirect is generated. With * you'd end up with http://*/ 
redir.html which isn't valid.

--
Rich Bowen
rbowen@rcbowen.com
http://drbacchus.com/




Re: [users@httpd] mixing dynamic and static virtual host definitions

Posted by Matt Price <ma...@utoronto.ca>.
  On 10-10-25 12:23 PM, Rich Bowen wrote:
>
> On Oct 25, 2010, at 12:07 PM, Matt Price wrote:
> The solution is to put a ServerName (and possibly one or more 
> ServerAlias directives) in the second VirtualHost.
>
thank you.  Things seem to work now -- though I confess to being a bit 
surprised that ServerName * will work in this instance.  And it would 
rbe nice to be able to specify a root location for requests without a 
HOST header.  But that will doubtless come.  Thanks so much!

Matt


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mixing dynamic and static virtual host definitions

Posted by Rich Bowen <rb...@rcbowen.com>.
On Oct 25, 2010, at 12:07 PM, Matt Price wrote:

> ok, I'm trying to understand but I guess I don't quite get it.  If I  
> have a file like this:
>
>
> <VirtualHost *:80>
>    DocumentRoot /home/drupal-commons/drupal_commons
>
>    ServerName tdhc.digitalcommons.ca
>
> </VirtualHost>
>
> <VirtualHost *:80>
>    UseCanonicalName    Off
>
>    VirtualDocumentRoot /var/www/%0
>
>    Options All
>
>    ServerAdmin matt.price@utoronto.ca
>
>    # Store uploads in /var/www/wp-uploads/$0
>
>    RewriteEngine On
>
>    RewriteRule ^/wp-uploads/(.*)$ /var/www/wp-uploads/%{HTTP_HOST}/$1
>
> </VirtualHost>
>
> all traffic, no matter the HOST of the request, gets directed to / 
> home/drupal-commons/drupal_commons.  If I reverse the stanzas, no  
> traffic ever gets directed there.  Is there no possible ordering in  
> which some traffic is matched by one of the stanzas, and some by  
> another?  And if not, is there a better trick to make that work?   
> Thanks very much,

You second vhost lacks a ServerName directive. As such, all traffic  
goes to the first (default) virtual host.

The solution is to put a ServerName (and possibly one or more  
ServerAlias directives) in the second VirtualHost.

--
Rich Bowen
rbowen@rcbowen.com
http://drbacchus.com/




Re: [users@httpd] mixing dynamic and static virtual host definitions

Posted by Matt Price <ma...@utoronto.ca>.
  On 10-10-25 11:21 AM, Eric Covener wrote:
>> then it pre-empts everything (not what I expected, since I'm using
>> ServerName, which I thought limited the application of this stanza to
>> instances in which HTTP_HOST matches. ServerName.
> Whichever one you put first is the default, which is used when there's
> no matching ServerName/ServerAlias.  The one where you left off
> ServerName/ServerAlias is only the default because it's first, not
> because it's not "constrained" to specific ServerNames -- it's
> actually unusuably when it's not first since it matches no server
> names.
ok, I'm trying to understand but I guess I don't quite get it.  If I 
have a file like this:


<VirtualHost *:80>                                                                                                                           

     DocumentRoot /home/drupal-commons/drupal_commons

     ServerName tdhc.digitalcommons.ca

</VirtualHost>                                                                                                                               

                                                                                                                                             

<VirtualHost *:80>                                                                                                                           

     UseCanonicalName    Off

     VirtualDocumentRoot /var/www/%0

     Options All

     ServerAdmin matt.price@utoronto.ca

     # Store uploads in /var/www/wp-uploads/$0

     RewriteEngine On

     RewriteRule ^/wp-uploads/(.*)$ /var/www/wp-uploads/%{HTTP_HOST}/$1

</VirtualHost>

all traffic, no matter the HOST of the request, gets directed to 
/home/drupal-commons/drupal_commons.  If I reverse the stanzas, no 
traffic ever gets directed there.  Is there no possible ordering in 
which some traffic is matched by one of the stanzas, and some by 
another?  And if not, is there a better trick to make that work?  Thanks 
very much,

Matt

ps -- Not sure but I may have solved this by adding a

ServerName *

to the dynamic VirtualHost stanza.  Is that bad practice?  And may I ask 
what I should do to capture requests that come in without a HOST: header 
(that is, in which the request is made directly by IP)?  I'd like to 
send those somewhere -- right now they go straight to 
tdhc.digitalcommons.ca, which I'd rather not have happen.  Thanks again 
very much,
Matt




---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mixing dynamic and static virtual host definitions

Posted by Eric Covener <co...@gmail.com>.
> then it pre-empts everything (not what I expected, since I'm using
> ServerName, which I thought limited the application of this stanza to
> instances in which HTTP_HOST matches. ServerName.

Whichever one you put first is the default, which is used when there's
no matching ServerName/ServerAlias.  The one where you left off
ServerName/ServerAlias is only the default because it's first, not
because it's not "constrained" to specific ServerNames -- it's
actually unusuably when it's not first since it matches no server
names.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mixing dynamic and static virtual host definitions

Posted by Matt Price <ma...@utoronto.ca>.
  On 10-10-23 09:33 AM, Eric Covener wrote:
>> 1) if the new stanza is placed above the old one, then ALL traffic arriving
>> at this server is directed to  /home/drupal-commons/drupal_commons.
>> 2) if the new stanza goes below the old, it is ignored entirely (this is
>> what I expected).
> You need 1  "NameVirtualHost *:80" to tell Apache to do name-based
> vhosts on those vhosts.   Then keep the generic one listed first, so
> it will be the default for *:80.
>
> (You might have "NameVirtualHost *" in your debian conf, but it needs
> to be a literal match.)
>
I have one NameVirtualHost *:80 which is in 
/etc/apache2/conf.d/ports.conf -- this is read before my site-specific 
conf stuff, I'm pretty sure.

I guess I don't quite understand what you're recommending.  Won't the 
generic stanza, which has dynamic matching:


<VirtualHost *:80>
         UseCanonicalName    Off
         VirtualDocumentRoot /var/www/%0
         Options All
         RewriteEngine On
         RewriteRule ^/wp-uploads/(.*)$ /var/www/wp-uploads/%{HTTP_HOST}/$1
</VirtualHost>

pr-empt any later stanza?  I thought that was the expected behaviour, 
and it explained to me why I have trouble when I put it first.  But if 
the site-specific stanza for the new drupal stie goes first,

<VirtualHost *:80>
             DocumentRoot /home/drupal-commons/drupal_commons
             ServerName drupalsite.example.com
</VirtualHost>

then it pre-empts everything (not what I expected, since I'm using 
ServerName, which I thought limited the application of this stanza to 
instances in which HTTP_HOST matches. ServerName.    Is the problem 
perhaps with the globbing in the directive declaration?  If so I don't 
see how to fix it, since I can't differentiate by IP (only one IP on 
this machine).

Thanks again for all your help.  Best,
Matt


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mixing dynamic and static virtual host definitions

Posted by Igor Galić <i....@brainsware.org>.
----- "Eric Covener" <co...@gmail.com> wrote:

> > 1) if the new stanza is placed above the old one, then ALL traffic
> arriving
> > at this server is directed to  /home/drupal-commons/drupal_commons.
> > 2) if the new stanza goes below the old, it is ignored entirely
> (this is
> > what I expected).
> 
> You need 1  "NameVirtualHost *:80" to tell Apache to do name-based
> vhosts on those vhosts.   Then keep the generic one listed first, so
> it will be the default for *:80.

That's default in the newer Debians.

> (You might have "NameVirtualHost *" in your debian conf, but it needs
> to be a literal match.)

This has been gotten rid off.

> -- 
> Eric Covener
> covener@gmail.com
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server
> Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org

-- 
Igor Galić

Tel: +43 (0) 664 886 22 883
Mail: i.galic@brainsware.org
URL: http://brainsware.org/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mixing dynamic and static virtual host definitions

Posted by Eric Covener <co...@gmail.com>.
> 1) if the new stanza is placed above the old one, then ALL traffic arriving
> at this server is directed to  /home/drupal-commons/drupal_commons.
> 2) if the new stanza goes below the old, it is ignored entirely (this is
> what I expected).

You need 1  "NameVirtualHost *:80" to tell Apache to do name-based
vhosts on those vhosts.   Then keep the generic one listed first, so
it will be the default for *:80.

(You might have "NameVirtualHost *" in your debian conf, but it needs
to be a literal match.)

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org