[dev] SERVER_NAME:SERVER_PORT and UseCanonicalName in Apache conflict

Barry Flanagan barryf-lists@online.ie
Thu, 15 Nov 2001 16:32:36 +0000


On Thursday 15 November 2001 11:56, you wrote:
> How about having the var, but setting it to the Apache Server_name by
> default... something like this (in the config file)
>
> #Server name... don't touch this unless you know what you are doing
> $SERVER_NAME=getenv('SERVER_NAME');
>


It's not so much the SERVER_NAME that is the problem, but the SERVER_PORT, which in our case is not necessarily the same at the Apache end as it is on the client end, due to the use of load balancers. SERVER_NAME is taken care of in the virtual host ServerName  directive.

Perhaps a directive similar to Apache's 'UseCanonicalName'  would do the trick, telling Horde to ignore the :PORT bit, and just use the defined ServerName.
e.g.

in horde/conf/horde.php

# Set to 1 for Horde to use only the ServerName, ignoring the port. e.g. the server will always appear as http://www.yourserver.com 
# or https://www.yourserver.com regardless of the actual port it is running on. Only useful if you are behind a load balancer and 
# your actual web server runs on ports other than the standard 80/443.
$conf['use_canonical_name'] = 1;

..and in horde/lib/Horde.php:

	if ($conf['use_canonical_name'] == 1) {
		$server = $HTTP_SERVER_VARS['SERVER_NAME'];
            } else {
		if (($HTTP_SERVER_VARS['SERVER_PORT'] != 80) &&( $HTTP_SERVER_VARS['SERVER_PORT'] != 443)) {
		$server = $HTTP_SERVER_VARS['SERVER_NAME'] . ':' . $HTTP_SERVER_VARS['SERVER_PORT'];
		}
            }


This works for me.

-Barry Flanagan

> ----- Original Message -----
> From: "Chuck Hagenbuch" <chuck@horde.org>
> To: <dev@lists.horde.org>
> Sent: Thursday, November 15, 2001 3:26 AM
> Subject: Re: [dev] SERVER_NAME:SERVER_PORT and UseCanonicalName in Apache
> conflict
>
> Quoting Barry Flanagan <barryf-lists@online.ie>:
> > Having a config value for $server and $secure_server might be another
> > alternative. The code as it is definately will cause grief to anyone else
> > with a load-balancer setup.
>
> Having a config value will cause grief to people who use virtualhosts and
> rely
> on $SERVER_NAME being set correctly.
>
> -chuck