You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Campbell, David" <Da...@granadamedia.com> on 2003/01/08 12:16:56 UTC

[users@httpd] Vhost cleverness


Hello clever people - I have a little apache question I was hoping someone
could answer:

We have ten loadbalanced Apache webservers all serving the same sets of
sites using name based virtual hosting.  In order to view the non
loadbalanced site on a single server we use ServerAliases to give unique
urls to each server:

<VirtualHost *>
    ServerName      www.mydomain.dom
    ServerAlias     server-1.mydomain.dom
    ServerAdmin   me@mydomain.dom
    DocumentRoot /content/rsync/mydomain.dom
    ErrorLog     /var/logs/errors/mydomain.dom
</VirtualHost>


This means that we have 10 different virtuals.conf for the virtual hosts - a
real pain to update.

What I want to do is pass variables as part of the ServerAlias

So I changed ServerName to server-1 in httpd.conf

and updated the vhosts to look like this

<VirtualHost *>
    ServerName      www.mydomain.dom
    ServerAlias     %{SERVER_NAME}.mydomain.dom
    ServerAdmin     me@mydomain.dom
    DocumentRoot /content/rsync/mydomain.dom
    ErrorLog     /var/logs/errors/mydomain.dom
</VirtualHost>


however this doesn't work  - server-1.mydomain.dom resolves to the default
vhost on server-1 not server-1.mydomain.dom

What am I doing wrong?  Did I go about this the right way?

Thanks in advance

Dave


********************************************************************** 
Please visit the official Granada website at www.granadamedia.com
for the latest company news.

This email and any files transmitted are confidential and intended 
solely for the use of the individual or entity to which they are 
addressed.  If you have received this email in error, please notify 
postmaster@granadamedia.com 

Thank you.
**********************************************************************


---------------------------------------------------------------------
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] Vhost cleverness

Posted by Kirk Jackson <ki...@mcs.vuw.ac.nz>.
I find mod_macro pretty useful to do something like this:

http://www.coelho.net/mod_macro/

Kirk

On Thu, 09 Jan 2003 01:24:20 -0500 Kirk Bailey <id...@netzero.net>
wrote:

> Zac Stevens wrote:
> > Hi David,
> > 
> > On Wed, Jan 08, 2003 at 11:16:56AM -0000, Campbell, David wrote:
> > <--snip-->
> > 
> >>This means that we have 10 different virtuals.conf for the virtual
> >hosts - a>real pain to update.
> >>
> >>What I want to do is pass variables as part of the ServerAlias
> > 
> If you only want ONE virtuals.conf file for all 10 domains, create a 
> soft link in each, each with the correct ownership for that domain,
> all pointing at one default file someplace else. Change that one, and
> all of them are changed. Does this help any?
> 
> [snip remaining bits]
> 
> 
> end
> 
> Respectfully,
>               Kirk D Bailey
> 
>               "Thou Art Free." - Eris
> 
> 
> ---------------------------------------------------------------------
> 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
> 

---------------------------------------------------------------------
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] Vhost cleverness

Posted by Kirk Bailey <id...@netzero.net>.
Zac Stevens wrote:
> Hi David,
> 
> On Wed, Jan 08, 2003 at 11:16:56AM -0000, Campbell, David wrote:
> <--snip-->
> 
>>This means that we have 10 different virtuals.conf for the virtual hosts - a
>>real pain to update.
>>
>>What I want to do is pass variables as part of the ServerAlias
> 
If you only want ONE virtuals.conf file for all 10 domains, create a 
soft link in each, each with the correct ownership for that domain, all 
pointing at one default file someplace else. Change that one, and all of 
them are changed. Does this help any?

[snip remaining bits]


end

Respectfully,
              Kirk D Bailey

              "Thou Art Free." - Eris


---------------------------------------------------------------------
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] Vhost cleverness

Posted by Zac Stevens <zt...@cryptocracy.com>.
Hi David,

On Wed, Jan 08, 2003 at 11:16:56AM -0000, Campbell, David wrote:
<--snip-->
> This means that we have 10 different virtuals.conf for the virtual hosts - a
> real pain to update.
> 
> What I want to do is pass variables as part of the ServerAlias

As Rich mentioned, that's not a valid syntax for ServerAlias.  Generally
speaking, there aren't any variables available for interpolation within
config directives unless specifically stated in the documentation.

While the usage you're trying never occurred to me before, it is quite
novel and it's a shame it doesn't work so simply.  But that's not what you
wanted to hear.

I'd think your best bet would be to look at using the ServerPath directive.
It will lead to uglier URLs when access the VH on a specific server, but
if you're using this largely for administrative purposes it could be good
enough.

http://httpd.apache.org/docs/vhosts/examples.html#serverpath

Failing that, the standard answer is to use a preprocessor on the
configuration file and use that to generate the per-server configuration.
If you currently have an automated method of distributing the configuration
to each server, the additional step won't cause you any problems.


Cheers,


Zac

---------------------------------------------------------------------
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] Vhost cleverness

Posted by Rich Bowen <rb...@rcbowen.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 8 Jan 2003, Campbell, David wrote:

> What I want to do is pass variables as part of the ServerAlias
>
> So I changed ServerName to server-1 in httpd.conf
>
> and updated the vhosts to look like this
>
> <VirtualHost *>
>     ServerName      www.mydomain.dom
>     ServerAlias     %{SERVER_NAME}.mydomain.dom
>     ServerAdmin     me@mydomain.dom
>     DocumentRoot /content/rsync/mydomain.dom
>     ErrorLog     /var/logs/errors/mydomain.dom
> </VirtualHost>
>
> however this doesn't work  - server-1.mydomain.dom resolves to the default
> vhost on server-1 not server-1.mydomain.dom
>
> What am I doing wrong?  Did I go about this the right way?

Well, what you're doing wrong is that this is not valid syntax for
ServerAlias. It doesn't understand variables. It thinks you want the
literal hostname "%{SERVER_NAME}.mydomain.dom", which is, of course, not
a valid hostname, but it's what you told it you wanted.

There are, perhaps, other ways to make this happen, but you can't make
up syntax for a directive and hope it works.

Modules like mod_backhand do load balancing. And I've seen a variety of
other suggested ways to handle this sort of load balancing. Perhaps
Google for apache load balancing, but I think it's also been addressed
here on the list, so there might be something in the archives.

- -- 
Nothing is perfekt. Certainly not me.
Success to failure. Just a matter of degrees.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Made with pgp4pine 1.75-6

iD8DBQE+HBJBXP03+sx4yJMRAgDWAKC3GPtVn+i+mkC3pYmrOODVODt/kwCg3W5O
iGW/2GiaYL+rrmh1/ONTrZY=
=byA4
-----END PGP SIGNATURE-----



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