39

I'm working on my first Java site. I'm running Apache Tomcat on port 8080, and Apache HTTPD on port 80. The current URL that I can access the site at is (for example) 123.4.5.6:8080. I want to remove the port number from the URL before I point the domain at the new IP.

At the moment I am only using Apache for phpmyadmin, however I plan on using it for CGI scripts and other stuff once I figure out mod_jk etc... So I don't want to change Tomcat's port to 80 and turn off Apache.

I hope this makes sense.

Eddie
  • 53,828
  • 22
  • 125
  • 145
Alan
  • 574
  • 2
  • 9
  • 16

5 Answers5

44

The correct way to do things is to leave Apache at 80 and Tomcat at 8080 and use a plug in (preferably mod_proxy) to proxy Tomcat from Apache. mod_proxy would only take you 10 minutes to set up.

This how-to is very simple to follow.

kgiannakakis
  • 103,016
  • 27
  • 158
  • 194
  • I'd recommend this too - best not have your JVM running as root unless you've got some other way of allowing it to bind to port 80. – Alnitak Mar 02 '09 at 20:13
  • 1
    mod_jk allows you to not run as root and still use port 80 to serve requests through Apache. – Mike Mar 02 '09 at 20:58
  • @kgiannakakis: do you prefer this over mod_jk? – cherouvim Mar 04 '09 at 17:12
  • mod_proxy is a newer module and is considered to be better than mod_jk. It is only supported from Apache's version 2.2 onwards. I personally have only used mod_proxy. – kgiannakakis Mar 05 '09 at 07:08
  • 2
    This answer could benefit greatly if some of the key points of the how-to were included here. Curretly it is little more then a link-only answer. – Angelo Fuchs Mar 12 '18 at 13:58
18

The usual way this is done, as you already mentioned, is to use mod_jk from Apache HTTPD to forward that content that you want to be processed by Tomcat.

There is a Quick HowTo at tomcat.apache.org. You need to do the following:

  • Copy mod_jk.so into the appropriate modules directory for Apache HTTPD.
  • Create a configuration file workers.properties
  • In Apache HTTPD's httpd.conf, add a section to configure mod_jk.
  • Ensure that Tomcat is configured to accept the mod_jk protocol, which is usually on port 8009.

The lines in httpd.conf with JkMount:

JkMount  /examples/* worker1

tell Apache HTTPD which requests are to be forwarded to Tomcat.

Eddie
  • 53,828
  • 22
  • 125
  • 145
2

Both the helpful answers above are good, but I much prefer mod_proxy over mod_jk. There's no extra installation to do for mod_proxy, unlike mod_jk, and the setup is much easier. mod_jk gives you more control over detailed tuning of Tomcat parameters, but if you just want a simple redirect from Apache to Tomcat, mod_proxy is the way to go.

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96
gareth_bowles
  • 20,760
  • 5
  • 52
  • 82
1

If you want static content to be served by Apache instead of Tomcat you should use mod_jk : http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html

And what about SSL - if we want Apache to handle HTTPS, because it is faster then java/Tomcat?

bodrin
  • 516
  • 5
  • 9
0

you should configure your tomcat using this link. for tomcat 7 http://tomcat.apache.org/tomcat-7.0-doc/proxy-howto.html

Haid
  • 111
  • 2
  • 10