Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How to forward request from Apache server to Tomcat 7

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
typing mistake C:\apache-tomcat-7.0.32\confworkers.properties --> C:\apache-tomcat-7.0.32\conf\workers.properties
 
Ranch Hand
Posts: 75
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tanks for reply.
How can I make it for www.stock-domain.com ?
 
K. Gil
Ranch Hand
Posts: 75
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try
JkMount /* ajp13

this will put mapping for top level application.
 
Saloon Keeper
Posts: 22524
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Frank VanOor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't play dumb with me! But you can try this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic