Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I redirect from Apache to Tomcat?

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.

like image 346
Alan Avatar asked Mar 02 '09 20:03

Alan


People also ask

Can Apache and Tomcat run on same port?

You cannot configure Tomcat to use the same port. An alternative would be to configure Apache to work as a reverse proxy for a specific location. For instance, make all requests going to /myapp to be routed or bridged to Tomcat which would be running on a different port.

What is the use of redirect port in Tomcat?

The only thing that the connector needs for the redirect to work is the “redirectPort” property, which should specify the secure (HTTPS) port on the proxy (not Tomcat). This connector can be used for both the non-secure and secure reverse proxy connections.


2 Answers

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.

like image 134
kgiannakakis Avatar answered Oct 20 '22 09:10

kgiannakakis


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.

like image 34
Eddie Avatar answered Oct 20 '22 08:10

Eddie