my dog learned polymorphism*
The moose likes Tomcat and the fly likes How to forward request from Apache server to Tomcat 7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to forward request from Apache server to Tomcat 7" Watch "How to forward request from Apache server to Tomcat 7" New topic
Author

How to forward request from Apache server to Tomcat 7

Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49
hi,

I've installed Apache 2.0.64 (latest release for windows) and Tomcat 7.0.32.
All incoming HTTP requests should be forwarded to Tomcat. But I don't manage having it working , nothing is forwarded to Tomcat :-(

Apache installation : C:\Apache-Group\Apache2\...
Tomcat installation : C:\apache-tomcat-7.0.32\...
Web Appl installation : C:\apache-tomcat-7.0.32\webapps\stockdomain

Changes for Apache2:

1. modifying C:\Apache-Group\Apache2\conf\httpd.conf

uncomment : LoadModule proxy_module modules/mod_proxy.so
add : include C:/apache-tomcat-7.0.32/conf/mod_jk.conf

2. copy mod_jk.so (from tomcat-connectors-1.2.37-windows-i386-httpd-2.0.x.zip) to C:\Apache-Group\Apache2\modules

Changes for Tomcat:

1. Adding file C:\apache-tomcat-7.0.32\confworkers.properties


# Define 1 real worker named ajp13
worker.list=ajp13

# Set properties for worker named ajp13 to use ajp13 protocol,
# and run on port 8009
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
worker.ajp13.lbfactor=50
worker.ajp13.cachesize=10
worker.ajp13.cache_timeout=600
worker.ajp13.socket_keepalive=1
worker.ajp13.socket_timeout=300


2. Adding file C:\apache-tomcat-7.0.32\conf\mod_jk.conf


# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
# Update this path to match your conf directory location
JkWorkersFile c:/apache-tomcat-7.0.32/conf/workers.properties

# Where to put jk logs
# Update this path to match your logs directory location
JkLogFile c:/apache-tomcat-7.0.32/logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

# Send everything for context /ws to worker ajp13
JkMount /stockdomain ajp13
JkMount /stockdomain/* ajp13



When typing www.stock-domain.com , I receive the Apache welcome page.

Thanks for help,

Frank
Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49
typing mistake C:\apache-tomcat-7.0.32\confworkers.properties --> C:\apache-tomcat-7.0.32\conf\workers.properties
K. Gil
Ranch Hand

Joined: Apr 29, 2011
Posts: 75

JkMount /stockdomain ajp13
JkMount /stockdomain/* ajp13


When typing www.stock-domain.com , I receive the Apache welcome page.


mapping is not for top domain, mapping is for path /stockdomain
so only requests that goes to apache for www.stock-domain.com/stockdomain/*
will be passed to tomcat.
Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49

Tanks for reply.
How can I make it for www.stock-domain.com ?
K. Gil
Ranch Hand

Joined: Apr 29, 2011
Posts: 75

try
JkMount /* ajp13

this will put mapping for top level application.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

Incidentally, mod_jk and mod_proxy are 2 different ways of connecting Apache and Tomcat, so you don't need both of them. Officially, mod_proxy is the 'preferred' way, and it's definitely less work to configure. Although the extra options that mod_jk requires may be an indication that it is more tunable. I haven't used mod_jk in so many years that I don't remember its virtues. Which back then were clouded by the mod_jk2/mod_jk3 debacle. Which, thankfully, has been resolved.


Customer surveys are for companies who didn't pay proper attention to begin with.
Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49
I've added JkMount /* ajp13 at the end if the file mod_jk.conf.

Now, when entering www.stock-domain.com, I see the Tomcat welcome page.
Any suggestion how to forward to "http://www.stock-domain.com/stockdomain/financeMainLayout.htm".

Thanks,


Frank

K. Gil
Ranch Hand

Joined: Apr 29, 2011
Posts: 75

good, now all requests to your domain are passed from Apache to Tomcat.

When I'm trying
"www.stock-domain.com/stockdomain/"
it redirects me to:
"www.stock-domain.com/stockdomain/financeMainLayout.htm"
and that means that document "financeMainLayout.htm" is set as welcome page for your application already.

So to make your app available at top domain as a default app, you can simply remove webapps/ROOT and rename your app from "stockdomain" to "ROOT", and restart tomcat. If you have stockdomain.war
then stop tomcat, remove webapps/ROOT, remove webapps/stockdomain directory, rename stockdomain.war to ROOT.war and start tomcat. Some may say it's not the best way, but it's the easiest and quickest way to make it happen.

Otherwise, the file $TOMCAT_HOME/conf/Catalina/localhost/ROOT.xml must be created by you by hand with correct docBase to your webapps/stockdomain, or you can add your Context inside conf/server.xml with path="" and docBase pointed to your application dir.

It's up to you what solution you will choose.
Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49
Thanks a lot for information.

Renaming stockdomain to ROOT seems an overkill. www.stock-domain.com:8080 can be "exposed" to the world. Tomcat may handle all requests directly.
I only need one redirect : from www.stock-domain.com to http://127.0.0.1:8080/stockdomain/financeMainLayout.htm. Can this be specified somehow in apache config ?


thanks,

Frank
 
jQuery in Action, 2nd edition
 
subject: How to forward request from Apache server to Tomcat 7
 
Similar Threads
Apache 2.0.53 + Tomcat 5.5.7 integration on Windows using mod_jk
tomcat6 and apache
apache tomcat - integration
File uploading problem
ajp with mod_jk and 503 error