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
You can set the UseCanonicalName On inside httpd.conf for that.
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.
Created attachment 14857 [details] Apache httpd.conf
Created attachment 14858 [details] Apache vhost.conf
Created attachment 14859 [details] Mod_JK workers.properties
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.
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.
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.
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?
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.
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.
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.
(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.
Awesome William, Thanks a lot for your help with this.
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" ... />
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.