How to Redirect Your Tomcat or JBoss Over Port 80

How to Redirect Your Tomcat or JBoss Over Port 80

This article is for customers with a dedicated server, VPS or Cloud VPS.

There is more than one way to handle this. Below is one such method that works well on a production based environment for both Apache Tomcat and JBoss.

Requirements:

  • CentOS
  • Apache httpd and httpd-devel installed
  • Tomcat or JBoss installed and running on port 8080.
  • Root or sudo access.

Install Tomcat Connector 1.2 (mod_jk)

# wget http://opensource.become.com/apache//tomcat/tomcat-connectors/jk/source/jk-1.2.31/tomcat-connectors-1.2.31-src.tar.gz
# tar xvzftomcat-connectors-1.2.31-src.tar.gz
# cd tomcat-connectors-1.2.31/native
# ./configure --with-apxs=/usr/sbin/apxs
# make
# su -c 'make install'
# cd ../conf/
# cp httpd_jk.conf /etc/httpd/conf.d/
# cp workers.properties /etc/httpd/conf/

Edit /etc/httpd/conf/workers.properties so that it has the following worker info after the manager entries:

worker.list=worker1 (for first worker)
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13

The port 8009 is the port found in tomcats coyote connector port in tomcat/conf/server.xml. Its also the same port for jboss using ports-default.

Finally you need to edit your virtualhost entry in either httpd.conf or its own file in /etc/httpd/conf.d/ (best practice is to use use separate file for each domain in /etc/httpd/con.d/)

Add the following JkMounts to your virtualhost entry just before the closing VirtualHost tag:

JkAutoAlias /opt/tomcat/webapps
JkMount /* worker1
JkMount /*/* worker1
JkMount /somefolder/* worker1
 
No need to change any configurations in Tomcat or Jboss.
 
Restart httpd and then Tomcat or Jboss.
 
You can also run multiple instances of Tomcat or JBoss servers with the above method.
 
After the first worker in workers.properties, create new one:
worker.list=worker2 (for second worker)
worker.worker2.port=8109 (Updated port which must be unique as with 8080/8180)
worker.worker2.host=localhost
worker.worker2.type=ajp13
 
Then include the following in the VirtualHost entry for new domain:
JkAutoAlias /opt/tomcat2/webapps
JkMount /* worker2
JkMount /*/* worker2
JkMount /somefolder/* worker2
 
Be sure to change port 8080, 8009, 8005 to 8180, 8109, 8105 in server.xml of tomcat.
For JBoss, just change the ports to ports-01 instead of ports-default in jboss-service.properties in jboss/server/servername/conf/
 
JBoss 5 and up now manages those ports in jboss/server/servername/conf/server/servername/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml
 
We will be happy to help you with these configurations. Just holler by submitting a support ticket.

If you don't want the hassle of managing your Tomcat environment yourself, start using a Java web host today.

  • 273 Users Found This Useful
Was this answer helpful?

Related Articles

Spring Framework

Need to develop Plain Old JAVA Objects? Want to have fun developing your application? Then we...

Subdomain Handling Tutorial

This tutorial explains how you can host subdomains with JavaPipe's Tomcat hosting. This is...

Pointer Domain Handling Tutorial

This tutorial explains how you can host pointer domains with a Java web hosting package from...

Choosing between JBoss7's Standalone or Domain features.

JBoss 7 introduced new feature called managed domains. Basically this is a multi-server...

How do I restart my tomcat?

However, if you have a private Tomcat instance with a Java host like us, then you have the...