You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Alessandro Fantuzzi <fa...@o-one.net> on 2009/04/10 19:32:26 UTC

[users@httpd] Third level domain

Hi ,
how do I set up Apache and Tomcat to serve two different web applications.
One application must respond when you visit www.site.com the other when 
you visit a third level domain like admin.site.com

Thanks


-- 

Alessandro Fantuzzi - O-one s.r.l.
E-mail: fantuzzi@o-one.net <ma...@o-one.net>
Software developer

www.o-one.net <http://www.o-one.net>

-------------------------------------------------------------------
Via Dante Zanichelli, 61 - 42100 Reggio Emilia
Tel. 0522 930078 - Fax. 0522 387947
-------------------------------------------------------------------
Via Stendhal, 36 - 20144 Milano
Tel 02.42292057 - Fax 02.47770936
-------------------------------------------------------------------

STRICTLY PERSONAL AND CONFIDENTIAL This message may contain confidential 
and proprietary material for the sole use of the intended recipient. Any 
review or distribution by others is strictly prohibited. If you are not 
the intended recipient please contact the sender and delete all copies. 
The contents of this message that do not relate to the official business 
of our company shall be understood as neither given nor endorsed by it.
-------------------------------------------------------------------

Re: [users@httpd] Third level domain

Posted by Krist van Besien <kr...@gmail.com>.
On Fri, Apr 10, 2009 at 9:46 PM, Alessandro Fantuzzi <fa...@o-one.net> wrote:

> In server.xml I created two Hosts

You don't need to do this in an apache + tomcat config. Just have one
tomcat host, with the two webapps in separate contexts, and let apache
handle the virtual hosts.

Krist




-- 
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Third level domain

Posted by Alessandro Fantuzzi <fa...@o-one.net>.
André Warnier ha scritto:
>
> Check #1:
> Presumably, you have Tomcat right now configured so that if you 
> request "http://www.company.com:8080/site_prod" or 
> "http://www.company.com:8080/site_admin", it calls the corresponding 
> application, right ?
Correct
>
> Check #2:
> I will also suppose that the DNS hostnames "www.company.com" and 
> "admin.company.com" resolve to the same IP address, this being the IP 
> address of the host where Apache and Tomcat are running, right ?
>
Correct
>
> There are different ways in which you can achieve what you want.
>
> In the meantime, considering that you are naming Apache httpd in your 
> configuration, let's suppose for now that you also need the Apache 
> httpd for some other reason, and let's thus do it with a front-end 
> Apache.
I need Apache in front of Tomcat
>
> Even there, there are several possibilities.
>
> You would want Apache (httpd) to act as a front-end for the Tomcat 
> server, and to "distribute" the calls to the /site_prod and 
> /site_admin applications under Tomcat.
> Apache can do that, using either one of the following "proxy modules" :
> - mod_proxy via HTTP
> - mod_proxy via AJP
> - mod_jk via AJP
> Are you familiar with any of those ?
> Is one of them already set up on your system ?
mod_jk
> Do you have a preference ?
I was thinking about mod_jk
>
> Next, presumably, you also want that in the process Apache makes the 
> calls appear like you are calling the top-level (or default) 
> application of two different sites, right ?
> I mean, you want your clients to call
> http://www.company.com  and not http://www.company.com/site_prod
> Yes ?
Correct
>
> So basically, what we want to achieve is :
>
> browser :     http://www.mycompany.com      http://admin.mycompany.com
> 1) goes to :         apache httpd host         same apache httpd host
> 2) changed to:  localhost:xxxx/site_prod      localhost:xxxx/site_admin
>   (where xxxx is the listening port of Tomcat on the same host)
> 3) sent to Tomcat (using mod_proxy_http, mod_proxy_ajp, or mod_jk)
> 4) calls Tomcat app     /site_prod                   /site_admin
> and back
>
> For (1), the DNS part must be working.
It is working
> You will probably also need to understand Virtual Hosts, so you might 
> as well read this too :
> http://httpd.apache.org/docs/2.2/vhosts/
> (read the section about Name-based Virtual Hosts)
> For (2), you will need some rewriting of the URL.
> Read this :
> http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
> For (3), we will need an Apache/Tomcat Connector.
> If one is already installed and working, it will be a lot easier.
> Is there ?
As you can see from the configuration I posted I am using mod_jk
>
> Otherwise, I suggest mod_jk, but that is only a personal preference, 
> because I know it better than the others.
> For (4), these apps need to be installed and working in Tomcat.
> Are they ? How do you call them, right now ?
The apps are installed and working in Tomcat. I have no problem when I 
call them direcly on Tomcat port like this
http://www.mycompany.com:8080/site_prod
and
http://www.mycompany.com:8080/site_admin

As you said what I want to achieve is calling one this way
http://www.mycompany.com
and the other that way
http://admin.mycompany.com
 
>
>
>> Here are the info about production environment.
>>
>> LINUX   APACHE     2.0.59
>> TOMCAT     5.5.20
>> JVM    1.5
>>
>> I read the documentation for both Apache httpd and Tomcat, and I also 
>> had some testing on my testing environment, which is somewhat different.
>>
>> Windows XP Professional
>> APACHE     2.0.63
>> Tomcat         6.0.14
>> JVM    1.5
>>
>> This is what we want to obtain:
>> when the user calls http://www.site.com the contents must be served 
>> by the application intalled in /site_prod under Tomcat.
>> When the user calls a particular third level domain, say 
>> http://admin.site.com the contents must be served by the application 
>> installed in /site_admin
>>
>> This is how I configured Apache httpd and Tomcat
>>
>> ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
>>
>>
>> httpd.conf:
>>
>> here I created two VirtualHosts
>>
>> <VirtualHost *:80>
>> ServerName    admin.site.com
>>
>> DocumentRoot    "webapps/site_admin"
>>
>> JkMount     /site_admin/*.jsp worker1
>> JkMount     /* worker1
>>
>> RewriteEngine on
>>
>> [...](Some rewrite rules)
>>
>> [...](Log files)
>>
>> </VirtualHost>
>>
>>
>> <VirtualHost *:80>
>> ServerName    site.com
>>
>> DocumentRoot    "webapps/site_prod"
>>
>> JkMount     /site_prod/*.jsp worker1
>> JkMount     /* worker1
>>
>> [...](Some rewrite rules)
>>
>> [...](Log files)
>>
>> </VirtualHost>
>>
>> ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
>>
>>
>> In server.xml I created two Hosts
>>
>> <Host appBase="webapps\" autoDeploy="true" debug="0" 
>> name="admin.site.com" unpackWARs="true">
>>    <Context debug="1" docBase="web\" path=""/>
>>    <Valve className="org.apache.catalina.valves.AccessLogValve" 
>> directory="logs" pattern="common" prrefix="home_access_log."
>>        resolveHosts="false" suffix=".txt"/>
>> </Host>
>>       <Host appBase="webapps\" autoDeploy="true" debug="0" 
>> name="www.site.com" unpackWARs="true">
>>    <Context debug="1" docBase="web\" path=""/>
>>    <Valve className="org.apache.catalina.valves.AccessLogValve" 
>> directory="logs" pattern="common" prrefix="home_access_log."
>>        resolveHosts="false" suffix=".txt"/>
>> </Host>
>>
>> ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
>>
>>
>> What is strange is that when both applications are up and running 
>> everithing seem to go the right way.
>> I mean, when I call www.site.com I get a response from the 
>> application sitting on /site_prod
>> And when I call admin.site.com I get a response from the application 
>> sitting on /site_admin
>> But if I turn off the application installed in /site_admin , instead 
>> of receving an error message, I get a page from the application in 
>> /site_prod
>>
>> I don' t know if this is a correct behaviour or if my configuration 
>> is messed up.
>>
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server 
> Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


-- 

Alessandro Fantuzzi - O-one s.r.l.
E-mail: fantuzzi@o-one.net <ma...@o-one.net>
Software developer

www.o-one.net <http://www.o-one.net>

-------------------------------------------------------------------
Via Dante Zanichelli, 61 - 42100 Reggio Emilia
Tel. 0522 930078 - Fax. 0522 387947
-------------------------------------------------------------------
Via Stendhal, 36 - 20144 Milano
Tel 02.42292057 - Fax 02.47770936
-------------------------------------------------------------------

STRICTLY PERSONAL AND CONFIDENTIAL This message may contain confidential 
and proprietary material for the sole use of the intended recipient. Any 
review or distribution by others is strictly prohibited. If you are not 
the intended recipient please contact the sender and delete all copies. 
The contents of this message that do not relate to the official business 
of our company shall be understood as neither given nor endorsed by it.
-------------------------------------------------------------------

Re: [users@httpd] Third level domain

Posted by André Warnier <aw...@ice-sa.com>.
Alessandro Fantuzzi wrote:
[...]

> 
> If I don' t go wrong the domain admin.site.com  is considered to be a 
> "third level domain" related to www.site.com
> 
I believe the following :
.com, .biz, etc.. are called "top level domains" or TLD (for obvious 
reasons).
mycompany.com, yourcompany.biz etc.. may be called "second-level 
domains", which in this case would make "www.yourcompany.biz" AND 
"admin.yourcompany.biz" be third-level domains.

The fact that "www" is traditionally chosen for website servers, and 
often for convenience made to resolve to the same IP as 
"yourcompany.biz", is just a choice.  Other than that, the name "www" 
for a host has no special DNS meaning as compared to "admin".

But that's not the main issue here.

To summarise : you have one Tomcat, one Apache httpd, and you want :
- that the requests to "http://www.yourcompany.com/" would go to the 
Tomcat application deployed under the /site_prod context
- that the requests to "http://admin.yourcompany.com/" would go to the 
Tomcat application deployed under the /site_admin context
both in the same Tomcat.

Check #1:
Presumably, you have Tomcat right now configured so that if you request 
"http://www.company.com:8080/site_prod" or 
"http://www.company.com:8080/site_admin", it calls the corresponding 
application, right ?

Check #2:
I will also suppose that the DNS hostnames "www.company.com" and 
"admin.company.com" resolve to the same IP address, this being the IP 
address of the host where Apache and Tomcat are running, right ?
(If not, then that is the first thing that you should organise, 
otherwise the rest will not work).

There are different ways in which you can achieve what you want.

The first thing you should now, is that strictly-speaking, to do just 
the above, you do not need an Apache httpd in front of Tomcat.  You 
could do this with Tomcat alone, and it may simplify your configuration 
and make your life easier, if you don't need Apache for anything else.
Let us know if you would prefer a Tomcat-only solution.

In the meantime, considering that you are naming Apache httpd in your 
configuration, let's suppose for now that you also need the Apache httpd 
for some other reason, and let's thus do it with a front-end Apache.

Even there, there are several possibilities.

You would want Apache (httpd) to act as a front-end for the Tomcat 
server, and to "distribute" the calls to the /site_prod and /site_admin 
applications under Tomcat.
Apache can do that, using either one of the following "proxy modules" :
- mod_proxy via HTTP
- mod_proxy via AJP
- mod_jk via AJP
Are you familiar with any of those ?
Is one of them already set up on your system ?
Do you have a preference ?

Next, presumably, you also want that in the process Apache makes the 
calls appear like you are calling the top-level (or default) application 
of two different sites, right ?
I mean, you want your clients to call
http://www.company.com  and not http://www.company.com/site_prod
Yes ?

So basically, what we want to achieve is :

browser :     http://www.mycompany.com      http://admin.mycompany.com
1) goes to :         apache httpd host         same apache httpd host
2) changed to:  localhost:xxxx/site_prod      localhost:xxxx/site_admin
   (where xxxx is the listening port of Tomcat on the same host)
3) sent to Tomcat (using mod_proxy_http, mod_proxy_ajp, or mod_jk)
4) calls Tomcat app     /site_prod                   /site_admin
and back

For (1), the DNS part must be working.
You will probably also need to understand Virtual Hosts, so you might as 
well read this too :
http://httpd.apache.org/docs/2.2/vhosts/
(read the section about Name-based Virtual Hosts)
For (2), you will need some rewriting of the URL.
Read this :
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
For (3), we will need an Apache/Tomcat Connector.
If one is already installed and working, it will be a lot easier.
Is there ?
Otherwise, I suggest mod_jk, but that is only a personal preference, 
because I know it better than the others.
For (4), these apps need to be installed and working in Tomcat.
Are they ? How do you call them, right now ?












> Here are the info about production environment.
> 
> LINUX   APACHE     2.0.59
> TOMCAT     5.5.20
> JVM    1.5
> 
> I read the documentation for both Apache httpd and Tomcat, and I also 
> had some testing on my testing environment, which is somewhat different.
> 
> Windows XP Professional
> APACHE     2.0.63
> Tomcat         6.0.14
> JVM    1.5
> 
> This is what we want to obtain:
> when the user calls http://www.site.com the contents must be served by 
> the application intalled in /site_prod under Tomcat.
> When the user calls a particular third level domain, say 
> http://admin.site.com the contents must be served by the application 
> installed in /site_admin
> 
> This is how I configured Apache httpd and Tomcat
> 
> ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
> 
> 
> httpd.conf:
> 
> here I created two VirtualHosts
> 
> <VirtualHost *:80>
> ServerName    admin.site.com
> 
> DocumentRoot    "webapps/site_admin"
> 
> JkMount     /site_admin/*.jsp worker1
> JkMount     /* worker1
> 
> RewriteEngine on
> 
> [...](Some rewrite rules)
> 
> [...](Log files)
> 
> </VirtualHost>
> 
> 
> <VirtualHost *:80>
> ServerName    site.com
> 
> DocumentRoot    "webapps/site_prod"
> 
> JkMount     /site_prod/*.jsp worker1
> JkMount     /* worker1
> 
> [...](Some rewrite rules)
> 
> [...](Log files)
> 
> </VirtualHost>
> 
> ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
> 
> 
> In server.xml I created two Hosts
> 
> <Host appBase="webapps\" autoDeploy="true" debug="0" 
> name="admin.site.com" unpackWARs="true">
>    <Context debug="1" docBase="web\" path=""/>
>    <Valve className="org.apache.catalina.valves.AccessLogValve" 
> directory="logs" pattern="common" prrefix="home_access_log."
>        resolveHosts="false" suffix=".txt"/>
> </Host>
>       <Host appBase="webapps\" autoDeploy="true" debug="0" 
> name="www.site.com" unpackWARs="true">
>    <Context debug="1" docBase="web\" path=""/>
>    <Valve className="org.apache.catalina.valves.AccessLogValve" 
> directory="logs" pattern="common" prrefix="home_access_log."
>        resolveHosts="false" suffix=".txt"/>
> </Host>
> 
> ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
> 
> 
> What is strange is that when both applications are up and running 
> everithing seem to go the right way.
> I mean, when I call www.site.com I get a response from the application 
> sitting on /site_prod
> And when I call admin.site.com I get a response from the application 
> sitting on /site_admin
> But if I turn off the application installed in /site_admin , instead of 
> receving an error message, I get a page from the application in /site_prod
> 
> I don' t know if this is a correct behaviour or if my configuration is 
> messed up.
> 


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Third level domain

Posted by Alessandro Fantuzzi <fa...@o-one.net>.
André Warnier ha scritto:
> Alessandro Fantuzzi wrote:
>> Hi ,
>> how do I set up Apache and Tomcat to serve two different web 
>> applications.
>> One application must respond when you visit www.site.com the other 
>> when you visit a third level domain like admin.site.com
>>
> I don't really know what you mean by "third level domain" in that 
> context, but in both Apache httpd and Tomcat, serving different 
> hostnames is usually something one does with Virtual Hosts.
> That is explained for both in their respective on-line documentation 
> pages.
> See httpd.apache.org and tomcat.apache.org.
>
> If after reading that, you would have further questions, ask again but 
> I suggest that supply some details about what versions you use, on 
> what system(s), and your configuration.
>

Ok.

If I don' t go wrong the domain admin.site.com  is considered to be a 
"third level domain" related to www.site.com

Here are the info about production environment.

LINUX   
APACHE     2.0.59
TOMCAT     5.5.20
JVM    1.5

I read the documentation for both Apache httpd and Tomcat, and I also 
had some testing on my testing environment, which is somewhat different.

Windows XP Professional
APACHE     2.0.63
Tomcat         6.0.14
JVM    1.5

This is what we want to obtain:
when the user calls http://www.site.com the contents must be served by 
the application intalled in /site_prod under Tomcat.
When the user calls a particular third level domain, say 
http://admin.site.com the contents must be served by the application 
installed in /site_admin

This is how I configured Apache httpd and Tomcat

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

httpd.conf:

here I created two VirtualHosts

<VirtualHost *:80>
ServerName    admin.site.com

DocumentRoot    "webapps/site_admin"

JkMount     /site_admin/*.jsp worker1
JkMount     /* worker1

RewriteEngine on

[...](Some rewrite rules)

[...](Log files)

</VirtualHost>


<VirtualHost *:80>
ServerName    site.com

DocumentRoot    "webapps/site_prod"

JkMount     /site_prod/*.jsp worker1
JkMount     /* worker1

[...](Some rewrite rules)

[...](Log files)

</VirtualHost>

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

In server.xml I created two Hosts

<Host appBase="webapps\" autoDeploy="true" debug="0" 
name="admin.site.com" unpackWARs="true">
    <Context debug="1" docBase="web\" path=""/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" 
directory="logs" pattern="common" prrefix="home_access_log."
        resolveHosts="false" suffix=".txt"/>
</Host>
       
<Host appBase="webapps\" autoDeploy="true" debug="0" name="www.site.com" 
unpackWARs="true">
    <Context debug="1" docBase="web\" path=""/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" 
directory="logs" pattern="common" prrefix="home_access_log."
        resolveHosts="false" suffix=".txt"/>
</Host>

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

What is strange is that when both applications are up and running 
everithing seem to go the right way.
I mean, when I call www.site.com I get a response from the application 
sitting on /site_prod
And when I call admin.site.com I get a response from the application 
sitting on /site_admin
But if I turn off the application installed in /site_admin , instead of 
receving an error message, I get a page from the application in /site_prod

I don' t know if this is a correct behaviour or if my configuration is 
messed up.

-- 

Alessandro Fantuzzi - O-one s.r.l.
E-mail: fantuzzi@o-one.net <ma...@o-one.net>
Software developer

www.o-one.net <http://www.o-one.net>

-------------------------------------------------------------------
Via Dante Zanichelli, 61 - 42100 Reggio Emilia
Tel. 0522 930078 - Fax. 0522 387947
-------------------------------------------------------------------
Via Stendhal, 36 - 20144 Milano
Tel 02.42292057 - Fax 02.47770936
-------------------------------------------------------------------

STRICTLY PERSONAL AND CONFIDENTIAL This message may contain confidential 
and proprietary material for the sole use of the intended recipient. Any 
review or distribution by others is strictly prohibited. If you are not 
the intended recipient please contact the sender and delete all copies. 
The contents of this message that do not relate to the official business 
of our company shall be understood as neither given nor endorsed by it.
-------------------------------------------------------------------

Re: [users@httpd] Third level domain

Posted by André Warnier <aw...@ice-sa.com>.
Alessandro Fantuzzi wrote:
> Hi ,
> how do I set up Apache and Tomcat to serve two different web applications.
> One application must respond when you visit www.site.com the other when 
> you visit a third level domain like admin.site.com
> 
I don't really know what you mean by "third level domain" in that 
context, but in both Apache httpd and Tomcat, serving different 
hostnames is usually something one does with Virtual Hosts.
That is explained for both in their respective on-line documentation pages.
See httpd.apache.org and tomcat.apache.org.

If after reading that, you would have further questions, ask again but I 
suggest that supply some details about what versions you use, on what 
system(s), and your configuration.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org