You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steffen Heil <li...@steffen-heil.de> on 2010/11/19 16:48:48 UTC

Several hosts within one tomcat / catch-all problem

Hi

We have a web application which usually runs on a certain host all alone -
it is the only context for that host.
However, it allows to use different hostnames and therefore we use aliases
in our server.xml per host.

Now more and more users of those application want to use more subdomains and
we have lots of trouble keeping the server.xml updates with all those
hostnames.

It would be a huge advantage to be able to tell tomcat to use all subdomains
of a given domain in one step.
Such as
<Alias>*.domain.tdl</Alias>

Or
<Alias catchAll="true">domain.tld</Alias>

So here are my questions:

1) Can this somehow be archived using tomcat 6? (We are currently running
6.0.29.)
2) Can the somehow be archived using tomcat 7?

(As I believe (and fear) the answer to the first two questions are "no", two
more:)
3) Would it be difficult to add this feature?
4) Where would I start to work on if I tried to create a patch for tomcat
myself?
5) Would there be any chances to get that patch later-on included into
trunk?

Regards,
  Steffen


Re: Several hosts within one tomcat / catch-all problem

Posted by Pid <pi...@pidster.com>.
On 19/11/2010 15:48, Steffen Heil wrote:
> Hi
> 
> We have a web application which usually runs on a certain host all alone -
> it is the only context for that host.
>
> However, it allows to use different hostnames and therefore we use aliases
> in our server.xml per host.
> 
> Now more and more users of those application want to use more subdomains and
> we have lots of trouble keeping the server.xml updates with all those
> hostnames.
> 
> It would be a huge advantage to be able to tell tomcat to use all subdomains
> of a given domain in one step.
> Such as
> <Alias>*.domain.tdl</Alias>

Can you make that host the defaultHost in the Engine definition?


p


> Or
> <Alias catchAll="true">domain.tld</Alias>
> 
> So here are my questions:
> 
> 1) Can this somehow be archived using tomcat 6? (We are currently running
> 6.0.29.)
> 2) Can the somehow be archived using tomcat 7?
> 
> (As I believe (and fear) the answer to the first two questions are "no", two
> more:)
> 3) Would it be difficult to add this feature?
> 4) Where would I start to work on if I tried to create a patch for tomcat
> myself?
> 5) Would there be any chances to get that patch later-on included into
> trunk?
> 
> Regards,
>   Steffen
> 


Re: AW: Several hosts within one tomcat / catch-all problem

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steffan,

On 11/24/2010 8:22 AM, Steffen Heil wrote:
> This cannot be done with defaultHost, can it?

Now I understand, and you are correct.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkztbVAACgkQ9CaO5/Lv0PBoOACgv8nlpjcSJnF6gSBci+Zc3RR6
mDwAn2HsDSmJ21vvFYL2XDz9WMd46XOe
=85fQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AW: Several hosts within one tomcat / catch-all problem

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

André,

On 11/24/2010 8:38 AM, André Warnier wrote:
> But even if this is an outside opinion by a non-Java non-Tomcat expert,
> it should not be too difficult to find the code which matches hostnames
> and aliases with the request Host: header, and change it from an exact
> to a regexp match, no ?
> Or introduce a new <AliasMatch> tag ? (that may be more ambitious, but
> maybe more elegant)

As Konstantin pointed out, all that stuff is in the "Mapper" (which is
org.apache.tomcat.util.http.mapper.Mapper).

I would say that using an <AliasMatch> would be a good idea because a)
it mirrors httpd-style configuration where <Foo> does exact matches
while <FooMatch> allows regular expressions, etc. and b) it shouldn't
diminish performance of the existing <Alias> code -- that is, you only
pay for it if you need it.

Steffen, care to log an enhancement request in bugzilla?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkztbeQACgkQ9CaO5/Lv0PADLQCgnlWy5+D+3JdxyW65PG+ITlcf
ey8AoJNxXJJE4KE6iehVMyGfj0gfe+/T
=uhVA
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AW: Several hosts within one tomcat / catch-all problem

Posted by André Warnier <aw...@ice-sa.com>.
Steffen Heil wrote:
> Hi
> 
>> Perhaps I don't understand, but I agree with Pid's suggestion: just use
>> defaultHost -- that's what it's for, right?
> 
> Yes, if you have only one.
> 
> However we have the following setup:
> 
> App1: domain1.tld, www.domain1.tld
> App2: domain2.tld, www.domain2.tld, additional.domain2.tld
> App3: domain3.tld, www.domain3.tld, another.domain3.tld
> 
> Now, defaultHost resolves the issue for ONE of these.
> But what we really need id:
> 
> App1: domain1.tld, *.domain1.tld
> App2: domain2.tld, *.domain2.tld
> App3: domain3.tld, *.domain3.tld
> 
> This cannot be done with defaultHost, can it?
> 

You are right, it cannot.

But even if this is an outside opinion by a non-Java non-Tomcat expert, it should not be 
too difficult to find the code which matches hostnames and aliases with the request Host: 
header, and change it from an exact to a regexp match, no ?
Or introduce a new <AliasMatch> tag ? (that may be more ambitious, but maybe more elegant)





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


AW: Several hosts within one tomcat / catch-all problem

Posted by Steffen Heil <li...@steffen-heil.de>.
Hi

> Perhaps I don't understand, but I agree with Pid's suggestion: just use
> defaultHost -- that's what it's for, right?

Yes, if you have only one.

However we have the following setup:

App1: domain1.tld, www.domain1.tld
App2: domain2.tld, www.domain2.tld, additional.domain2.tld
App3: domain3.tld, www.domain3.tld, another.domain3.tld

Now, defaultHost resolves the issue for ONE of these.
But what we really need id:

App1: domain1.tld, *.domain1.tld
App2: domain2.tld, *.domain2.tld
App3: domain3.tld, *.domain3.tld

This cannot be done with defaultHost, can it?

Regards,
  Steffen


Re: Several hosts within one tomcat / catch-all problem

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Konstantin,

On 11/19/2010 11:59 AM, Konstantin Kolinko wrote:
> 2010/11/19 Steffen Heil <li...@steffen-heil.de>:
>> Hi
>>
>> We have a web application which usually runs on a certain host all alone -
>> it is the only context for that host.
>> However, it allows to use different hostnames and therefore we use aliases
>> in our server.xml per host.
>>
>> Now more and more users of those application want to use more subdomains and
>> we have lots of trouble keeping the server.xml updates with all those
>> hostnames.
>>
>> It would be a huge advantage to be able to tell tomcat to use all subdomains
>> of a given domain in one step.
>> Such as
>> <Alias>*.domain.tdl</Alias>
> 
> I like it.

Perhaps I don't understand, but I agree with Pid's suggestion: just use
defaultHost -- that's what it's for, right?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkzsNQ8ACgkQ9CaO5/Lv0PBHLACdHpOI/NY4k8ttCYJq9bezk/Ji
CFgAn1FVvTxhDFYmUEFACRMG2Lw8WlJj
=ak33
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Several hosts within one tomcat / catch-all problem

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/11/21 David Fisher <df...@jmlafferty.com>:
>> and use JMX or call mapper.addHostAlias(..) directly to add aliases
>> programmatically at runtime.  (though there is no guarantee that the
>> Mapper API does not change between Tomcat minor releases).
>
> I investigated what an implementation of this might look like at a higher level. In looking through the Tomcat interfaces it looks like this is similar to the notion of automatically creating Context for users with a UserConfig listener.
>
> It would be an AliasConfig class extending HostConfig.
>  <Listener className="my.web.server.listener.package.AliasConfig" aliases="/path/to/alias/file"/>
>
> Then in the start event function it is as simple as "host.addAlias(subDomainName);" for each alias found in the aliases file.
>
> Does this make sense?
>

It does make sense.

o.a.c.connector.MapperListener updates the mapper when the aliases
list in the Host is changed.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Several hosts within one tomcat / catch-all problem

Posted by David Fisher <df...@jmlafferty.com>.
Hi Konstantin,

> BTW, you can put those names in an external file and use it in the
> server.xml as an XML entity. Like the example in
> http://wiki.apache.org/tomcat/FAQ/Password

Inspired by this thread and having a similar issue in maintaining virtual host aliases I edited my server.xml as follows:

I added this before the <Server>.

<!DOCTYPE aliases-xml [
  <!ENTITY aliases SYSTEM "/path/to/network/storage/aliases.txt">
]>

I moved my <Alias> tags to /path/to/network/storage/aliases.txt, substituting &aliases;

This works very well. Thanks!

> and use JMX or call mapper.addHostAlias(..) directly to add aliases
> programmatically at runtime.  (though there is no guarantee that the
> Mapper API does not change between Tomcat minor releases).

I investigated what an implementation of this might look like at a higher level. In looking through the Tomcat interfaces it looks like this is similar to the notion of automatically creating Context for users with a UserConfig listener.

It would be an AliasConfig class extending HostConfig.
  <Listener className="my.web.server.listener.package.AliasConfig" aliases="/path/to/alias/file"/>

Then in the start event function it is as simple as "host.addAlias(subDomainName);" for each alias found in the aliases file.

Does this make sense?

Regards,
Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Several hosts within one tomcat / catch-all problem

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/11/19 Steffen Heil <li...@steffen-heil.de>:
> Hi
>
> We have a web application which usually runs on a certain host all alone -
> it is the only context for that host.
> However, it allows to use different hostnames and therefore we use aliases
> in our server.xml per host.
>
> Now more and more users of those application want to use more subdomains and
> we have lots of trouble keeping the server.xml updates with all those
> hostnames.
>
> It would be a huge advantage to be able to tell tomcat to use all subdomains
> of a given domain in one step.
> Such as
> <Alias>*.domain.tdl</Alias>

I like it.

> Or
> <Alias catchAll="true">domain.tld</Alias>

Or a regexp...? (Or any configurable way). (Use some algorithm name
instead of "catchAll" argument naming).

>
> So here are my questions:
>
> 1) Can this somehow be archived using tomcat 6? (We are currently running
> 6.0.29.)
> 2) Can the somehow be archived using tomcat 7?
>
> (As I believe (and fear) the answer to the first two questions are "no", two
> more:)
> 3) Would it be difficult to add this feature?
> 4) Where would I start to work on if I tried to create a patch for tomcat
> myself?

The mapping is done in
org.apache.tomcat.util.http.mapper.Mapper

Note, that Mapper.find(MapElement[], String) and similar methods
perform a binary search,
so how your use case can be plugged into it?

All requests go through Mapper, so its performance is important.

Maybe allow to apply additional processing if no explicit match was found?

> 5) Would there be any chances to get that patch later-on included into
> trunk?

I, personally, like the general idea of making it more flexible.

You may file an enhancement request in the Bugzilla (if there is none
yet), though one with a patch has more chances.

http://tomcat.apache.org/bugreport.html#Patches_and_enhancement_requests

>

As a workaround, I can recommend looking at the UrlRewrite filter,
http://www.tuckey.org/urlrewrite/

It might be that it will help, but I am no so sure.


BTW, you can put those names in an external file and use it in the
server.xml as an XML entity. Like the example in
http://wiki.apache.org/tomcat/FAQ/Password

and use JMX or call mapper.addHostAlias(..) directly to add aliases
programmatically at runtime.  (though there is no guarantee that the
Mapper API does not change between Tomcat minor releases).


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org