You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Brian Akins <br...@turner.com> on 2005/08/18 20:45:41 UTC

canonical port

We have servers that listen on a ports other than 80 which our load 
balancers communicate with.  The client hits port 80 on the load 
balancer.  I hacked up a quick module to try to emulate the old "Port" 
config directive so that redirects go to the "canonical" port.
     It does this by changing r->parsed_uri.port, based on what 
ap_get_server_port does

This normally works.  Now we have a server with a large number of vhosts 
and it appears to work for some and not for others.  That is my current 
problem.

Surely I'm not the only one who has a similar setup.  Is there a config 
thing I'm just missing or do we need to bring back Port?


-- 
Brian Akins
Lead Systems Engineer
CNN Internet Technologies

Re: canonical port

Posted by Sander Temme <sa...@temme.net>.
On Aug 18, 2005, at 12:18 PM, Brian Akins wrote:

> Hmm, it seems if useCanonicalName is off and you use Servername  
> like this:
>
> ServerName www.domain.com:80
>
> That ap_get_servername will use that port unless the client used a  
> port in the Host: header.
>
> My testing seems to confirm this.  Is this correct?

Looking at server/core.c:950:

http://svn.apache.org/viewcvs.cgi/*checkout*/httpd/httpd/trunk/server/ 
core.c

You see that what this function returns depends on the  
UseCanonicalName setting. If that's on, we first look in the  
server_rec. This value gets set when the ServerName directive  
includes :port. Otherwise, we look at the port the request connection  
came in on, and the final fallback is the default port.

If UseCanonicalName is off, we look at the parsed_uri first, then at  
the connection, then at the server_rec and finally fall back to the  
default port.

Now, I think modules should use ap_get_server_port() to obtain this  
information. However, one sees in the Apache 2.0 mod_jk.c:496:

     /* get the real port (otherwise redirect failed) */
     /* XXX: use apache API for getting server port
      *
      * Pre 1.2.7 versions used:
      * s->server_port = r->connection->local_addr->port;
      */
     s->server_port  = ap_get_server_port(r);

Whoops. There may be more like that out there: YMMV.

S.

-- 
sander@temme.net              http://www.temme.net/sander/
PGP FP: 51B4 8727 466A 0BC3 69F4  B7B8 B2BE BC40 1529 24AF


Re: canonical port

Posted by Brian Akins <br...@turner.com>.
Hmm, it seems if useCanonicalName is off and you use Servername like this:

ServerName www.domain.com:80

That ap_get_servername will use that port unless the client used a port 
in the Host: header.

My testing seems to confirm this.  Is this correct?




-- 
Brian Akins
Lead Systems Engineer
CNN Internet Technologies

Re: canonical port

Posted by Brian Akins <br...@turner.com>.
Sander Temme wrote:

> 
> Do you do more/different things?


This is what I do in translate_name:

  if((conf = ap_get_module_config(r->server->module_config, 
&port_module)) != NULL) {
         if(conf->port != NOCONFIG) {
             /*looking at server/core.c, ap_get_server_port This looks 
to be the best place
              * UseCanonicalName MUST be off, or this is ignored*/
             r->parsed_uri.port     = conf->port;
             r->parsed_uri.port_str = conf->port_str;
         }
     }


This is a fixed version which appears to have fixed my original breakage.




-- 
Brian Akins
Lead Systems Engineer
CNN Internet Technologies

Re: canonical port

Posted by Sander Temme <sa...@temme.net>.
Brian,

On Aug 18, 2005, at 11:45 AM, Brian Akins wrote:

> We have servers that listen on a ports other than 80 which our load  
> balancers communicate with.  The client hits port 80 on the load  
> balancer.  I hacked up a quick module to try to emulate the old  
> "Port" config directive so that redirects go to the "canonical" port.
>     It does this by changing r->parsed_uri.port, based on what  
> ap_get_server_port does

I'm in much the same boat. My module substitutes the outside  
listening port in the post_config handler:

static int bn_post_config(apr_pool_t *pconf, apr_pool_t *plog,  
apr_pool_t *ptemp, server_rec *s)
{
     bn_cfg *cfg;
     server_rec *swalk;

     for (swalk = s; swalk; swalk = swalk->next) {
         cfg = BNSrvConfig(swalk);
         if (cfg->enabled) {
             swalk->port = cfg->listenport;
         }
     }
     return OK;
}

This has been lightly tested and is based on ap_get_server_port  
looking in that particular place first. So far no horrible side  
effects have been observed.

Do you do more/different things?

S.

-- 
sander@temme.net              http://www.temme.net/sander/
PGP FP: 51B4 8727 466A 0BC3 69F4  B7B8 B2BE BC40 1529 24AF


Re: canonical port

Posted by Jim Jagielski <ji...@jaguNET.com>.
No, you're not unique. You'll see that 2.1 behaves somewhat different
than 2.0, when I was trying to come up with a more "logical and
expected" (Ha! :) ) behavior...

On Aug 18, 2005, at 2:45 PM, Brian Akins wrote:

> We have servers that listen on a ports other than 80 which our load  
> balancers communicate with.  The client hits port 80 on the load  
> balancer.  I hacked up a quick module to try to emulate the old  
> "Port" config directive so that redirects go to the "canonical" port.
>     It does this by changing r->parsed_uri.port, based on what  
> ap_get_server_port does
>
> This normally works.  Now we have a server with a large number of  
> vhosts and it appears to work for some and not for others.  That is  
> my current problem.
>
> Surely I'm not the only one who has a similar setup.  Is there a  
> config thing I'm just missing or do we need to bring back Port?
>
>
> -- 
> Brian Akins
> Lead Systems Engineer
> CNN Internet Technologies
>
>