I am coming from this SO however my case is not on Tomcat, but JBoss EAP 6. So suppose I have two web apps app1 and app2 running on JBoss AS 6:
- app1 on
http://localhost:8080/app1
- app2 on
http://localhost:8080/app2
However I want to configure Tomcat so that they run in root context behind separate ports:
- app1 on
http://localhost:8081
- app2 on
http://localhost:8082
How can I make it on JBoss EAP 6? Note this answer doesn't work for me as it targets JBoss 5.
JBoss AS7 version of the configuration discussed in the answer for AS6 with multiple http connectors and a rewrite valve.
See also:
Following way worked out for me. Have a look.
First go the server location and copy the
default
folder with new name. In my scenario will name it,server_uat
.Copy conf, lib, and server folder from
default
intoserver_uat
folder.Direct to
jboss-service.xml
(which is inserver_uat
)Uncomment the
ServiceBindingManager
mbean
and change the ServerName toports-01
.You can even use
ports-02
orports-03
. The required configurations are already done by JBoss in thedocs/examples/binding-manager.xml
file.Once the change is made after adding
ports-01
tombean
code fragment. It should lool like the following.Using the command prompt, direct to the bin folder and run the
server_uat
server instance with the following command.Windows:
Linux:
FYI:
EDIT: These instructions are for JBoss AS6 as requested in the original question. AS7 has different configuration file syntax.
Your problem has two parts:
Getting JBoss to listen on multiple ports
This one is easy.
Add lines like these to
$JBOSS_HOME/server/default/deploy/jbossweb.sar/server.xml
Observe the following messages in the log when server boots up:
Note: If you want to do it "properly" you should use placeholders instead of hardcoded numbers and edit
$JBOSS_HOME/server/default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml
to define them. But, unless you need to manage ports via the management UI, it will be an overkill.Dispatch requests to port 8081 to app1 and port 8082 to app2
This is much harder. JBoss uses its own Tomcat engine that does not support multiple webapp roots (appBase attribute does not work). Thus it is impossible to configure two different directories for your connectors. It is possible to add virtual hosts and use
jboss-web.xml
in each app to configure which vhost it responds to, but that means your have to use different names in client URL-s.You have two options here.
Option 1: JBoss RewriteValve
Add this to
Host
configuration element (before other valve definitions) in$JBOSS_HOME/server/default/deploy/jbossweb.sar/server.xml
Create a file
$JBOSS_HOME/server/default/conf/jboss.web/localhost/rewrite.properties
with the following contents:Note: You may need to create the
$JBOSS_HOME/server/default/conf/jboss.web/localhost/
directory, it does not exist by default.Note2: Location of the
rewrite.properties
depends on the placement of theValve
tag inserver.xml
. The most intuitive placement is with otherValve
elements. However it is valid directly underEngine
as well. In this caserewrite.properties
file needs to be moved up one directory.Option 2: Servlet filter in ROOT context
Deploy a servlet filter to
$JBOSS_HOME/server/default/deploy/ROOT.war/
that dispatches requests based on incoming port. You can either roll out your own custom filter implementation or use UrlRewriteFilter with a configuration that looks like this:See also:
EDIT: Given the complexity of JBoss configuration you may also opt for an Apache based reverse proxy that sits in front of the app server.