You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Julien Martin <ba...@gmail.com> on 2010/12/11 10:47:02 UTC

Virtual host, alias and context parameters

Hello,
I need to achieve the following:
-Having two domain names pointing to the same tomcat application and MOST
IMPORTANTLY, having for each domain name a unique context parameter
(therefore different for each domain name) that I will retrieve in my app to
display different information to my users accordingly.
How can I achieve this with tomcat? Is that possible?
Thanks in advance,
J.

Re: Virtual host, alias and context parameters

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/12/11 Julien Martin <ba...@gmail.com>:
> -MOST
> IMPORTANTLY, having for each domain name a unique context parameter
> (therefore different for each domain name) that I will retrieve in my app to
> display different information to my users accordingly.
>

You can create the following file, as mentioned in [1]:
$CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default

There you can add <Environment> entries, as you would in one's
webapp's context.xml, as documented in [2].

That "context.xml.default" file serves as the default for context.xml
files of webapps on that specific host.

Then in your webapp you will use JNDI to get the value of that
environment variable.

YMMV

[1] http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
[2] http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#context.xml_configuration

Best regards,
Konstantin Kolinko

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


Re: Virtual host, alias and context parameters

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

Julien,

On 12/11/2010 10:50 AM, Julien Martin wrote:
> Thanks all for your replies and sorry for the upper case.
> I am already parsing the domain name in my app and I think I will stick to
> that.

I'm a bit late to the thread, but here's a suggestion: use a Filter.

With a Filter, you can control the logic for determining the
configuration in a single place (the Filter code) and then place an
object into the request scope that contains whatever configuration your
webapp uses -- like paths to resources like images, css files, etc. and
strings like the "name" of the website, etc.

This is an easy way to do private-labeling.

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

iEYEARECAAYFAk0Hl6kACgkQ9CaO5/Lv0PCPYACeN9tjpppMyy7QkeI3oTNXnrAJ
6bUAoI5f/pFHe04gO7r1yA0W81N1NO/4
=HDOl
-----END PGP SIGNATURE-----

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


Re: Virtual host, alias and context parameters

Posted by Julien Martin <ba...@gmail.com>.
Thanks all for your replies and sorry for the upper case.
I am already parsing the domain name in my app and I think I will stick to
that.
Regards,
J.

2010/12/11 André Warnier <aw...@ice-sa.com>

> Let me add something to my previous answer, to kind of wrap up also what
> the others responded.
>
> (a) With the Alias solution, there will be a single copy of your web
> application.
> To react differently depending on the hostname that the users call up, that
> web application can get the hostname of the request that was sent, and do
> conditional things depending on it.
>
> (b) With the virtual Host solution, there will be multiple copies of your
> web application, one for each different domain name.
>
> The second solution may seem like a duplication.  However, you have to
> think a bit in advance.  Currently, maybe the difference between the
> application for users of host A and the application for the users of host B
> are really small, and you do not think that you need 2 separate web apps.
> But it most cases, you will find out that these differences increase with
> time, and that you will find yourself adding always more conditional code to
> your application, and making it more and more complicated and less and less
> maintainable.
> In that case, it is probably better to start with solution (b) in the first
> place.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Virtual host, alias and context parameters

Posted by André Warnier <aw...@ice-sa.com>.
Let me add something to my previous answer, to kind of wrap up also what the others responded.

(a) With the Alias solution, there will be a single copy of your web application.
To react differently depending on the hostname that the users call up, that web 
application can get the hostname of the request that was sent, and do conditional things 
depending on it.

(b) With the virtual Host solution, there will be multiple copies of your web application, 
one for each different domain name.

The second solution may seem like a duplication.  However, you have to think a bit in 
advance.  Currently, maybe the difference between the application for users of host A and 
the application for the users of host B are really small, and you do not think that you 
need 2 separate web apps.
But it most cases, you will find out that these differences increase with time, and that 
you will find yourself adding always more conditional code to your application, and making 
it more and more complicated and less and less maintainable.
In that case, it is probably better to start with solution (b) in the first place.



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


Re: Virtual host, alias and context parameters

Posted by André Warnier <aw...@ice-sa.com>.
Julien Martin wrote:
> Hello,
> I need to achieve the following:
> -Having two domain names pointing to the same tomcat application and MOST
> IMPORTANTLY, having for each domain name a unique context parameter
> (therefore different for each domain name) that I will retrieve in my app to
> display different information to my users accordingly.
> How can I achieve this with tomcat? Is that possible?
> Thanks in advance,
> J.
> 

On mailing lists, CAPITALS are usually taken as the equivalent of shouting, which is not 
very nice in a first post.

Depending on your version of Tomcat (which you didn't tell us), you may want to have a 
look at the on-line documentation, starting from here :
http://tomcat.apache.org/

For the rest, I'll assume that you are using the current Tomcat 6.0.

You can achieve the domain names part using the proper DNS setup, and either Alias or 
Virtual Hosts in Tomcat.

For Alias, look here :
http://tomcat.apache.org/tomcat-6.0-doc/config/host.html
and look at Special Feature #4, Host name aliases

For Virtual Hosts, look here :
http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html

To get the hostname to which the request was addressed, you could search Google for :
HttpServletRequest.getServerName for examples.







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


Re: Virtual host, alias and context parameters

Posted by Pid <pi...@pidster.com>.
On 11/12/2010 09:47, Julien Martin wrote:
> Hello,
> I need to achieve the following:
> -Having two domain names pointing to the same tomcat application and MOST
> IMPORTANTLY, having for each domain name a unique context parameter
> (therefore different for each domain name) that I will retrieve in my app to
> display different information to my users accordingly.
> How can I achieve this with tomcat? Is that possible?
> Thanks in advance,
> J.

I guess you'll be using Tomcat 6.0.latest?

If your apps are deployed to the default host, or you've added aliases
for each domain to the same host, you'll have the first part solved.

The second part depends on whether you need to know the domain during a
request processing or some other non-request processing part of the app.

In the former case, you could look up the value you want by using the
requested host name as map key.  Otherwise you will need to deploy the
app once in two separate hosts.


p