Bug 34648 - AJP uses Host header not ServerName directive from Apache
AJP uses Host header not ServerName directive from Apache
Status: RESOLVED FIXED
Product: Tomcat 5
Classification: Unclassified
Component: Connector:AJP
Unknown
All All
: P3 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2005-04-27 17:12 UTC by Daniel Hopper
Modified: 2005-08-01 00:34 UTC (History)
1 user (show)



Attachments
Apache httpd.conf (6.20 KB, text/plain)
2005-04-27 17:37 UTC, Daniel Hopper
Details
Apache vhost.conf (155 bytes, text/plain)
2005-04-27 17:37 UTC, Daniel Hopper
Details
Mod_JK workers.properties (243 bytes, text/plain)
2005-04-27 17:37 UTC, Daniel Hopper
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Hopper 2005-04-27 17:12:34 UTC
Currently the implementation for which AJP1/3 Connector selects which host to
pass the request to is determined solely by the HTTP Host header.  It would be
nice if it could optionally use the ServerName directive that is passed from
Apache through mod_jk to the AJP1/3 Connector.  This would be create for ISP
hosting enviroments in which name based hosting may not always be the hosting
method.  Currently our setup we have some hosts that are name based and some
that are address based.  For address based hosts consider the following apache conf

<VirtualHost 192.168.2.100>
ServerName www.testhost.com
JkMount /* default
</VirtualHost>

and the associated tomcat host conf

<Host name="testhost" appBase="webapps">
  <Alias>www.testhost.com</Alias>
</Host>

Now this client is setup as and address based host.  Let also say that the
domain name www.testhost2.com resolves to 192.168.2.100 as well.  Since we don't
always manage the DNS and clients could have (N) domains pointing to their IP
address.  The domain www.testhost.com will work just fine but www.testhost2.com
will not, b/c the host header will have www.testhost2.com obviously instead of
www.testhost.com.  Now if tomcat had an option to use the ServerName directive
if it was passed this would then work for both the domains in question, as it
would lookup of www.testhost.com from ServerName passed through mod_jk instead
of just solely looking up the Host Header.

This obviously isn't a bug but a feature request, I know that other containers
do already do this like Resin, handles this situation just fine.

Tomcat Version: 5.5.9
Mod_JK: 1.2.10
Apache: 2.0.54
Comment 1 Mladen Turk 2005-04-27 17:25:25 UTC
You can set the
UseCanonicalName On inside httpd.conf for that.
Comment 2 Daniel Hopper 2005-04-27 17:31:19 UTC
I do have this directive configured with 

UseCanonicalName On

in httpd.conf, but it still doesn't select the host in tomcat based on the
ServerName directive in the VirtualHost directive block.
Comment 3 Daniel Hopper 2005-04-27 17:37:05 UTC
Created attachment 14857 [details]
Apache httpd.conf
Comment 4 Daniel Hopper 2005-04-27 17:37:28 UTC
Created attachment 14858 [details]
Apache vhost.conf
Comment 5 Daniel Hopper 2005-04-27 17:37:47 UTC
Created attachment 14859 [details]
Mod_JK workers.properties
Comment 6 Mladen Turk 2005-04-27 18:42:04 UTC
Again, this is not mod_jk bug, nor feature.
If you wish you can use mod_header and inside your
virtual host set the:

RequestHeader set HOST www.testhost.com

That'll do the trick.
Comment 7 Daniel Hopper 2005-04-27 19:10:07 UTC
We currently are using mod_header to rewrite the header, but the problem with
this is when it gets to tomcat and if you do a redirect it uses the new header.
 For instance if you are using mod_header and rewriting to www.testhost.com.
Lets say a user access www.testhost2.com and a redirect is done, it will
redirect back to www.testhost.com.  This is problamatic with portals.  Also,
with portals we may want to show different content if they are accessing the
site via www.testhost.com or from www.testhost2.com, and with the rewritten
header it will always appear to be from www.testhost.com.  We have been
uneventful in finding a work around for this which is what brought me here.  I
tried the exact same configuration with Resin, changing nothing in apache
besides adding the LoadModule for resin's module and it works just fine using
ServerName which is what I would like to see in tomcat.

I know this isn't a bug, but it doesn't follow the pattern you would expect.  I
would expect it to operate like resin did.
Comment 8 william.barker 2005-04-27 20:26:59 UTC
So it sounds like you want a Connector option to use request.getLocalName() 
(which is where the Apache ServerName ends up in Jk) for host mapping.  While 
not technically difficult to implement, it sounds fragile.
Comment 9 Daniel Hopper 2005-04-27 20:55:02 UTC
Thanks again for the quick response, yea that is what I am looking for.  Though
it would probably have to fall through some how as well, like trying to get the
request.getLocalName() if that is null falling back on the
request.getHeader("host") in place of it.  I think this is something that ISP
hosting enviroment, which is what we are, would find this quite useful.  As
currently we have been tossing up the idea of switching to Resin, which I would
rather not do as I have had great success with tomcat and would like to keep our
production enviroment running on tomcat.

What about this option would be fragile?
Comment 10 Mladen Turk 2005-04-28 07:08:33 UTC
The reason why it will be fragile is because it will break the HTTP
specs. Other reason is for cases where there is mod_proxy->mod_jk->tomcat.
In that case it will receive the middle host name instead the front one.

So, why don't you just put the multiple <Alias>...</Alias> for
that host in the server.xml.
Comment 11 Daniel Hopper 2005-04-28 14:34:33 UTC
B/c we don't always know what hosts a client may have.  If we are managing their
dns we would know and that isn't a terrible problem, but for other clients they
manage their own DNS and tend to by names up all the time and just point them to
their IP address and we would have no knowledge of the new host that is pointing
to our servers until we get a call from the client complaining about their new
domain not working.
Comment 12 Daniel Hopper 2005-04-28 15:49:48 UTC
Another thing we have some clients that have 50+ domain names.  This would mean
100+ Alias entries as well to accomidate for www.testhost.com and testhost.com
references that could be in the Host header.
Comment 13 william.barker 2005-04-29 19:19:07 UTC
(In reply to comment #8)
> So it sounds like you want a Connector option to use request.getLocalName() 
> (which is where the Apache ServerName ends up in Jk) for host mapping.  
While 
> not technically difficult to implement, it sounds fragile.

Reviewing the Catalina code, it looks like implementing an option (I'm 
thinking useIPVHosts="true") to do this should work fine.  I'll add it into 
the CVS later.
Comment 14 Daniel Hopper 2005-04-29 20:38:19 UTC
Awesome William,

Thanks a lot for your help with this.
Comment 15 william.barker 2005-04-30 05:35:07 UTC
The option has now been added to the CVS, and will appear in 5.5.10.

To enable it, use:
  <Connector protocol="AJP/1.3" useIPVHosts="true" ... />
Comment 16 Sven 2005-08-01 08:34:18 UTC
So the field was always there, but wasn't used?
(well, it was used by tomcat 4.1 ;-) )

I'm not quite sure, why the options is called useIPVHosts, but for me it's all
about moving the choice of the right vhost to apache. Haveing to configure the
same aliases in both tomcat and apache, that's what i'd call a fragile config.