You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by nohacks <ph...@gmail.com> on 2009/04/26 08:47:53 UTC
How do I host multiple websites with Apache2 and Tomcat Cluster ??
Hi All,
I have a question for any Apache Tomcat master.
How you host multiple websites with Apache2 and Tomcat Cluster ??
It would be nice to have separate log files ??
I am using AJP and wondering how this would work. Also, with sticky sessions
and separate websites ??
Thanks for all help.
Phil
====================
This is my 000-default file from etc/apache2/sites-enabled (ip's have been
changed for display)
=========================================
NameVirtualHost 22.33.444.114:80
<VirtualHost 22.33.444.114:80>
JkMount /*.jsp loadbalancer
JkMount /*.jsf loadbalancer
JkMount /servlet/* loadbalancer
JkMount /* loadbalancer
JkStripSession On
ServerAdmin webmaster@localhost
ServerName "www.testApp.com"
ServerAlias "www.testApp.com"
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
# This directive allows us to have apache2's default start
page
# in /apache2-default/, but still have / go to the right
place
RedirectMatch ^/$ /apache2-default/
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride all
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
FileETag None
ExpiresDefault "access plus 4 weeks"
# 480 weeks
<FilesMatch "\.(jsf|ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=490304000, public"
</FilesMatch>
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
</VirtualHost>
<VirtualHost *:80>
JkMount /*.jsp loadbalancer
JkMount /*.jsf loadbalancer
JkMount /servlet/* loadbalancer
JkMount /* loadbalancer
JkStripSession On
ServerAdmin webmaster@localhost
ServerName "www.testApp.com"
ServerAlias "www.testApp.com"
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
# This directive allows us to have apache2's default start
page
# in /apache2-default/, but still have / go to the right
place
RedirectMatch ^/$ /apache2-default/
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride all
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
FileETag None
ExpiresDefault "access plus 4 weeks"
# 480 weeks
<FilesMatch "\.(jsf|ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=490304000, public"
</FilesMatch>
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
</VirtualHost>
=========================================
Here is the workers.properties file.
=========================================
# workers.properties
ps=/
# list the workers by name
worker.list=tomcat1,tomcat2,tomcat3,loadbalancer
#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
# ----> lbfactor must be > 0
# ----> Low lbfactor means less work done by the worker.
# ------------------------
# First tomcat server
# ------------------------
worker.tomcat1.port=18009
worker.tomcat1.host=192.168.70.101
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=33
# ------------------------
# Second tomcat server
# ------------------------
worker.tomcat2.port=19009
worker.tomcat2.host=192.168.70.102
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=33
# ------------------------
# Third tomcat server
# ------------------------
worker.tomcat3.port=20009
worker.tomcat3.host=192.168.70.103
worker.tomcat3.type=ajp13
worker.tomcat3.lbfactor=33
# -----------------------
# Load Balancer worker
# ------------------------
#
# The loadbalancer (type lb) worker performs weighted round-robin
# load balancing with sticky sessions.
# Note:
# ----> If a worker dies, the load balancer will check its state
# once in a while. Until then all work is redirected to peer
# worker.
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat1,tomcat2,tomcat3
#
# END workers.properties
#
--
View this message in context: http://www.nabble.com/How-do-I-host-multiple-websites-with-Apache2-and-Tomcat-Cluster----tp23239694p23239694.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How do I host multiple websites with Apache2 and Tomcat Cluster
??
Posted by André Warnier <aw...@ice-sa.com>.
nohacks wrote:
...
>
> Currently I have my app deployed as ROOT in Tomcat. How do I change this for
> multiple apps? I am new to Apache and Tomcat deployments...
>
http://wiki.apache.org/tomcat/HowTo
#38
It's exactly the opposite of what you want to do, so maybe you can just
take it in reverse ?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How do I host multiple websites with Apache2 and Tomcat Cluster
??
Posted by Pid <p...@pidster.com>.
nohacks wrote:
> Hi Chris,
>
> Thanks for your very detailed response!!
>
> I will try that out Tues Morning and get back to you with any questions.
>
> I do have one.
>
> Currently I have my app deployed as ROOT in Tomcat. How do I change this for
> multiple apps? I am new to Apache and Tomcat deployments...
>
> For example I would like to have
>
> www.example.com load that is why I deployed as ROOT.war.
> www.additional.com
> www.extra.com
>
> I Read several articles about starting off Tomcat war files with
> www.example.com and not extra path stuff.
Plenty of info on the docs site, and usually a better source than
'articles' of unknown provenance:
http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html
p
> Thanks
> Phil
>
>
>
>
> Christopher Schultz-2 wrote:
> Phil,
>
> On 4/26/2009 2:47 AM, nohacks wrote:
>>>> How you host multiple websites with Apache2 and Tomcat Cluster ??
> When you say "multiple websites" do you mean "multiple webapps"? Serving
> multiple web applications should not be a problem at all:
>
>>>> JkMount /*.jsp loadbalancer
>>>> JkMount /*.jsf loadbalancer
> This appears to be a set up for a single webapp, but can certainly be
> used to power several sites:
>
> /app1/index.jsp
> /app2/index.jsp
> /app3/index.jsp
>
> All of these will be sent to Tomcat using the "loadbalancer" worker.
> Tomcat will determine which webapp should receive each request.
>
>>>> JkMount /servlet/* loadbalancer
> Use of the "/servlet" request dispatcher is not recommended. If you have
> servlets using this, you might want to consider migrating to a setup
> where each servlet is explicitly defined in your web.xml to make a
> unique URL. You may already be doing this but have retained the /servlet
> prefix for historical reasons. I figured I'm mention it, though.
>
>>>> JkMount /* loadbalancer
> Technically speaking, this JkMount covers all 3 previous JkMount
> statements, so the others are not necessary. But, since you are using
> httpd in the first place, why not have it serve your static content for
> you? If I were you, I'd remove this JkMount and direct httpd to serve
> static files for you, while delegating to Tomcat for things like JSPs
> and servlets.
>
> Also, I like to specifically mount each web application separately. I
> happen to use different workers for each webapp (I have separate
> back-end Tomcats for each one) so I /must/ do this, but it helps
> document the httpd configuration file, too:
>
> JkMount /app1/*.jsp loadbalancer
> JkMount /app1/*.jsf loadbalancer
>
> JkMount /app2/*.jsp loadbalancer
> JkMount /app2/*.jsf loadbalancer
>
> JkMount /app3/*.jsp loadbalancer
> JkMount /app3/*.jsf loadbalancer
>
>>>> It would be nice to have separate log files ??
> You can use separate log files within the same VirtualHost section by
> using environment variables:
>
> SetEnvIf Request_URI "^/app1/" app1
> CustomLog logs/app1.log env=app1
>
> See
> http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#customlog
>
>>>> I am using AJP and wondering how this would work. Also, with sticky
>>>> sessions
>>>> and separate websites ??
> The use of sticky sessions should have no impact on multiple webapps.
>
> -chris
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How do I host multiple websites with Apache2 and Tomcat Cluster
??
Posted by nohacks <ph...@gmail.com>.
Hi Chris,
Thanks for your very detailed response!!
I will try that out Tues Morning and get back to you with any questions.
I do have one.
Currently I have my app deployed as ROOT in Tomcat. How do I change this for
multiple apps? I am new to Apache and Tomcat deployments...
For example I would like to have
www.example.com load that is why I deployed as ROOT.war.
www.additional.com
www.extra.com
I Read several articles about starting off Tomcat war files with
www.example.com and not extra path stuff.
Thanks
Phil
Christopher Schultz-2 wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Phil,
>
> On 4/26/2009 2:47 AM, nohacks wrote:
>> How you host multiple websites with Apache2 and Tomcat Cluster ??
>
> When you say "multiple websites" do you mean "multiple webapps"? Serving
> multiple web applications should not be a problem at all:
>
>> JkMount /*.jsp loadbalancer
>> JkMount /*.jsf loadbalancer
>
> This appears to be a set up for a single webapp, but can certainly be
> used to power several sites:
>
> /app1/index.jsp
> /app2/index.jsp
> /app3/index.jsp
>
> All of these will be sent to Tomcat using the "loadbalancer" worker.
> Tomcat will determine which webapp should receive each request.
>
>> JkMount /servlet/* loadbalancer
>
> Use of the "/servlet" request dispatcher is not recommended. If you have
> servlets using this, you might want to consider migrating to a setup
> where each servlet is explicitly defined in your web.xml to make a
> unique URL. You may already be doing this but have retained the /servlet
> prefix for historical reasons. I figured I'm mention it, though.
>
>> JkMount /* loadbalancer
>
> Technically speaking, this JkMount covers all 3 previous JkMount
> statements, so the others are not necessary. But, since you are using
> httpd in the first place, why not have it serve your static content for
> you? If I were you, I'd remove this JkMount and direct httpd to serve
> static files for you, while delegating to Tomcat for things like JSPs
> and servlets.
>
> Also, I like to specifically mount each web application separately. I
> happen to use different workers for each webapp (I have separate
> back-end Tomcats for each one) so I /must/ do this, but it helps
> document the httpd configuration file, too:
>
> JkMount /app1/*.jsp loadbalancer
> JkMount /app1/*.jsf loadbalancer
>
> JkMount /app2/*.jsp loadbalancer
> JkMount /app2/*.jsf loadbalancer
>
> JkMount /app3/*.jsp loadbalancer
> JkMount /app3/*.jsf loadbalancer
>
>> It would be nice to have separate log files ??
>
> You can use separate log files within the same VirtualHost section by
> using environment variables:
>
> SetEnvIf Request_URI "^/app1/" app1
> CustomLog logs/app1.log env=app1
>
> See
> http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#customlog
>
>> I am using AJP and wondering how this would work. Also, with sticky
>> sessions
>> and separate websites ??
>
> The use of sticky sessions should have no impact on multiple webapps.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkn1x8kACgkQ9CaO5/Lv0PBKcACfZNKsAURI7lbVL3wW9VLpG1dc
> oekAn17a1fq3yRKs7cLu7qlgP/b4N31i
> =gfTd
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-do-I-host-multiple-websites-with-Apache2-and-Tomcat-Cluster----tp23239694p23269266.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How do I host multiple websites with Apache2 and Tomcat Cluster
??
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Phil,
On 4/26/2009 2:47 AM, nohacks wrote:
> How you host multiple websites with Apache2 and Tomcat Cluster ??
When you say "multiple websites" do you mean "multiple webapps"? Serving
multiple web applications should not be a problem at all:
> JkMount /*.jsp loadbalancer
> JkMount /*.jsf loadbalancer
This appears to be a set up for a single webapp, but can certainly be
used to power several sites:
/app1/index.jsp
/app2/index.jsp
/app3/index.jsp
All of these will be sent to Tomcat using the "loadbalancer" worker.
Tomcat will determine which webapp should receive each request.
> JkMount /servlet/* loadbalancer
Use of the "/servlet" request dispatcher is not recommended. If you have
servlets using this, you might want to consider migrating to a setup
where each servlet is explicitly defined in your web.xml to make a
unique URL. You may already be doing this but have retained the /servlet
prefix for historical reasons. I figured I'm mention it, though.
> JkMount /* loadbalancer
Technically speaking, this JkMount covers all 3 previous JkMount
statements, so the others are not necessary. But, since you are using
httpd in the first place, why not have it serve your static content for
you? If I were you, I'd remove this JkMount and direct httpd to serve
static files for you, while delegating to Tomcat for things like JSPs
and servlets.
Also, I like to specifically mount each web application separately. I
happen to use different workers for each webapp (I have separate
back-end Tomcats for each one) so I /must/ do this, but it helps
document the httpd configuration file, too:
JkMount /app1/*.jsp loadbalancer
JkMount /app1/*.jsf loadbalancer
JkMount /app2/*.jsp loadbalancer
JkMount /app2/*.jsf loadbalancer
JkMount /app3/*.jsp loadbalancer
JkMount /app3/*.jsf loadbalancer
> It would be nice to have separate log files ??
You can use separate log files within the same VirtualHost section by
using environment variables:
SetEnvIf Request_URI "^/app1/" app1
CustomLog logs/app1.log env=app1
See
http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#customlog
> I am using AJP and wondering how this would work. Also, with sticky sessions
> and separate websites ??
The use of sticky sessions should have no impact on multiple webapps.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkn1x8kACgkQ9CaO5/Lv0PBKcACfZNKsAURI7lbVL3wW9VLpG1dc
oekAn17a1fq3yRKs7cLu7qlgP/b4N31i
=gfTd
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How do I host multiple websites with Apache2 and Tomcat Cluster
??
Posted by nohacks <ph...@gmail.com>.
This is my httpd.conf file.
LoadModule jk_module /usr/lib/apache2/modules/mod_jk-1.2.27-httpd-2.2.6.so
JkStripSession On
JkMount /*.jsp loadbalancer
JkMount /*.jsf loadbalancer
# JkMount /*.jsp ajp13
# JkMount /*.jsf ajp13
JkWorkersFile workers.properties
JkShmFile /var/log/httpd/mod_jk.shm
JkLogFile /opt/apache2log/mod_jk.log
JkLogLevel info
# JkLogLevel debug
JkOptions +ForwardURIEscaped
JkOptions +ForwardDirectories
FileETag None
ExpiresDefault "access plus 4 weeks"
# 480 weeks
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=490304000, public"
</FilesMatch>
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
--
View this message in context: http://www.nabble.com/How-do-I-host-multiple-websites-with-Apache2-and-Tomcat-Cluster----tp23239694p23239712.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org