LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   SUSE / openSUSE (https://www.linuxquestions.org/questions/suse-opensuse-60/)
-   -   apache2 & tomcat5 - how to configure VIRTUAL HOSTS & JSP? (https://www.linuxquestions.org/questions/suse-opensuse-60/apache2-and-tomcat5-how-to-configure-virtual-hosts-and-jsp-298860/)

nicolasdiogo 03-07-2005 05:19 PM

apache2 & tomcat5 - how to configure VIRTUAL HOSTS & JSP?
 
Hello,

I have installed my SuSE 9.2 pro with a DHCP server, DNS server, and even LDAP authetication (thanks to help found on this forum!).
At present, I have also intalled my apache2 webserver easily, but I can not figure out how to configure tomcat5 to work with my apache2.
Let me make it clear that I have installed both packages, apache2 & tomcat5, accoding to SuSE's descriptions so I have the usual JSP pages working (/jsp-examples/ and /servlets/), however I do not understand how to configure Apache2 VIRTUAL HOSTS to serve JSP pages.
SuSE as you know comes with a mod_jk rpm which is easily installed and remaining of cofiguration is fairly straigth forward thanks to notes in the /var/ directory.
But even after a lot of time searching and reading I still can not setup the server.

I have tried ProxyPass and ProxyPassReturn as an alternative but that did not work.
And also tried [uri:/domainPath/*] configuration, again, without any lucky.

I swear that I have searched, but it seems that I still missing something!?

What I am seeking is to enable the following VIRTUAL HOSTS (with JSP & servlets) to be processed through tomcat5:

<VirtualHost *:80>

<IfDefine SSL>
SSLEngine off
</IfDefine>

DocumentRoot /srv/www/vhosts/brainpowered.net/
ServerName www.brainpowered.net
ServerAdmin admin@brainpowered.net

DirectoryIndex index.jsp index.html


</VirtualHost>



the default jk.conf (/etc/apache2/conf.d/jk.conf) is as follows:

########################start#############################
# simple configuration for apache (for AJP connector, modul mod_jk.so)

<IfModule mod_jk.c>

JkWorkersFile /etc/tomcat5/base/workers.properties
JkLogFile /var/log/tomcat5/base/mod_jk.log

# Log level to be used by mod_jk
JkLogLevel error

# The following line makes apache aware of the location of
# the /servlets-examples context
Alias /servlets-examples "/srv/www/tomcat5/base/webapps/servlets-examples"
<Directory "/srv/www/tomcat5/base/webapps/servlets-examples">
Options Indexes FollowSymLinks
allow from all
</Directory>


# The following line makes apache aware of the location of
# the /jsp-examples context
Alias /jsp-examples "/srv/www/tomcat5/base/webapps/jsp-examples"
<Directory "/srv/www/tomcat5/base/webapps/jsp-examples">
Options Indexes FollowSymLinks
allow from all
</Directory>

# The following line mounts all JSP files and the /servlet/ uri to tomcat
JkMount /servlets-examples/servlet/* ajp13
JkMount /jsp-examples/*.jsp ajp13

# The following line prohibits users from directly accessing WEB-INF
<Location "/jsp-examples/WEB-INF/">
AllowOverride None
deny from all
</Location>
<Location "/servlets-examples/WEB-INF/">
AllowOverride None
deny from all
</Location>

</IfModule>

########################end#############################

And the workers.properties file is:

#######################start#############################

# workers.properties -
#
# This file provides jk derived plugins with the needed information to
# connect to the different tomcat workers. Note that the distributed
# version of this file requires modification before it is usable by a
# plugin.
#
# As a general note, the characters $( and ) are used internally to define
# macros. Do not use them in your own configuration!!!
#
# Whenever you see a set of lines such as:
# x=value
# y=$(x)\something
#
# the final value for y will be value\something
#
# Normaly all you will need to do is un-comment and modify the first three
# properties, i.e. workers.tomcat_home, workers.java_home and ps.
# Most of the configuration is derived from these.
#
# When you are done updating workers.tomcat_home, workers.java_home and ps
# you should have 3 workers configured:
#
# - An ajp12 worker that connects to localhost:8007
# - An ajp13 worker that connects to localhost:8009
# - A jni inprocess worker.
# - A load balancer worker
#
# However by default the plugins will only use the ajp12 worker. To have
# the plugins use other workers you should modify the worker.list property.
#
#

# OPTIONS ( very important for jni mode )

#
# workers.tomcat_home should point to the location where you
# installed tomcat. This is where you have your conf, webapps and lib
# directories.
#
workers.tomcat_home=/var/tomcat3

#
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
workers.java_home=/opt/IBMJava2-13

#
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#
ps=/

#
#------ ADVANCED MODE ------------------------------------------------
#---------------------------------------------------------------------
#

#
#------ DEFAULT worket list ------------------------------------------
#---------------------------------------------------------------------
#
#
# The workers that your plugins should create and work with
#
# Add 'inprocess' if you want JNI connector
worker.list=ajp12, ajp13
# , inprocess


#
#------ DEFAULT ajp12 WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
#

#
# Defining a worker named ajp12 and of type ajp12
# Note that the name and the type do not have to match.
#
worker.ajp12.port=8007
worker.ajp12.host=localhost
worker.ajp12.type=ajp12
#
# 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.
worker.ajp12.lbfactor=1

#
#------ DEFAULT ajp13 WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
#

#
# Defining a worker named ajp13 and of type ajp13
# Note that the name and the type do not have to match.
#
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
#
# 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.
worker.ajp13.lbfactor=1

#
# Specify the size of the open connection cache.
#worker.ajp13.cachesize

#
#------ DEFAULT LOAD BALANCER WORKER DEFINITION ----------------------
#---------------------------------------------------------------------
#

#
# The loadbalancer (type lb) workers perform wighted 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
# workers.
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=ajp12, ajp13


#
#------ DEFAULT JNI WORKER DEFINITION---------------------------------
#---------------------------------------------------------------------
#

#
# Defining a worker named inprocess and of type jni
# Note that the name and the type do not have to match.
#
worker.inprocess.type=jni

#
#------ CLASSPATH DEFINITION -----------------------------------------
#---------------------------------------------------------------------
#

#
# Additional class path components.
#
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)tomcat.jar

#
# Setting the command line for tomcat.
# Note: The cmd_line string may not contain spaces.
#
worker.inprocess.cmd_line=start

# Not needed, but can be customized.
#worker.inprocess.cmd_line=-config
#worker.inprocess.cmd_line=$(workers.tomcat_home)$(ps)conf$(ps)server.xml
#worker.inprocess.cmd_line=-home
#worker.inprocess.cmd_line=$(workers.tomcat_home)

#
# The JVM that we are about to use
#
# This is for Java2
#
# Windows
worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)classic$(ps)jvm.dll
# IBM JDK1.3
#worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)classic$(ps)libjvm.so
# Unix - Sun VM or blackdown
#worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)lib$(ps)i386$(ps)classic$(ps)libjvm.so

#
# And this is for jdk1.1.X
#
#worker.inprocess.jvm_lib=$(workers.java_home)$(ps)bin$(ps)javai.dll


#
# Setting the place for the stdout and stderr of tomcat
#
worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr

#
# Setting the tomcat.home Java property
#
#worker.inprocess.sysprops=tomcat.home=$(workers.tomcat_home)

#
# Java system properties
#
# worker.inprocess.sysprops=java.compiler=NONE
# worker.inprocess.sysprops=myprop=mypropvalue

#
# Additional path components.
#
# worker.inprocess.ld_path=d:$(ps)SQLLIB$(ps)bin
#

#########################end#############################

Many, Many thanks in Advance!

Nicolas

nicolasdiogo 03-09-2005 01:41 PM

Maybe a solution!
 
i have been seeking for a solution and i think this may help others.

As SuSE 9.2 default configuration of mod_jk provides a worker.property file with pre-configured workers (apj12, apj13) we simply need to add jkMount'ers for JSP pages.

in the jk.conf file, i have added the following lines:

# mount all files ending with JSP
JkMount /*.jsp ajp13

# mount all files ending with JSPX
JkMount /*.jspx ajp13

# mount all files that are stored under SERVLET folder
JkMount /*/servlet/* ajp13

because I am using VIRTUAL HOSTS in apache2, i had to amend the configuration for the virtual host as:

<VirtualHost *:80>

<IfDefine SSL>
SSLEngine off
</IfDefine>

DocumentRoot /srv/www/vhosts/brainpowered.net/
ServerName www.brainpowered.net
ServerAdmin admin@brainpowered.net

DirectoryIndex index.jsp index.html

# withdrawing access to configuration folder
<Directory "/srv/www/vhosts/brainpowered.net/WEB-INF">
Options None
Deny from all
</Directory>


</VirtualHost>



additionally, we need to tell tomcat5 where the virtual host's file reside. We do that by amending the $CATALINA_BASE/base/server.xml file. And adding a host description for each VIRTUAL HOST of apache2:

<Host name="brainpowered.net" debug="1"
appBase="/srv/www/vhosts/brainpowered.net/"
unpackWARs="true">
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="brainpowered.net." suffix=".txt"
timestamp="true"/> -->
<Context path="" docBase="" debug="0"
reloadable="true" crossContext="true" />
<Alias>www.brainpowered.net</Alias>
</Host>

It works for me. And I hope it helps others as well.

Regards,


Nicolas

milhan 04-05-2007 09:06 AM

can't create new directories for servlets
 
hello

I have a small problem. I installed tomcat5 on my Suse 10.2 box, and both the apache and tomcat5 is up and running. The problem, now I have, is that I want to create new directories under webapps and put my servlets there so that I can run them from http://localhost:8080/

For instance, the servlets-examples that is in

/srv/www/tomcat5/base/webapps/servlets-examples works fine when I open the browser: http://localhost:8080/servlets-examples/

But now I want to create new directories such as project1.. for other servlets I want to host on my computer. So I created directory under webapps like:

/srv/www/tomcat5/base/webapps/project1

and created the WEB-INF, and classes under WEB-INF, set the right permissions. But when I open the browser, even if I stop and re-start the tomcat5, the url path:

http://localhost:8080/project1

is not accessible. The error I am getting is:

Code:

HTTP Status 404 - /project1/

type Status report

message /project1/

description The requested resource (/project1/) is not available.

Why is this happening? How can I fix this? I spent many hours researching it, but without luck.

Can anyone help me? I will appreciate.

regards.


All times are GMT -5. The time now is 02:33 AM.