How to run different applications on the same instance of JBoss AS 6 for different ports?

I come from this SO , but my business is not Tomcat, but JBoss EAP 6. So, suppose I have two applications 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 to run in the root context behind the individual ports:

  • app1 on http://localhost:8081
  • app2 on http://localhost:8082

How can I do this on JBoss EAP 6? Note this answer does not work for me as it targets JBoss 5.

+7
java tomcat servlets jboss
source share
2 answers

EDIT: These instructions are for JBoss AS6, as stated in the original question. AS7 has a different configuration file syntax.

Your problem consists of two parts:

  • Make JBoss listen on multiple ports.
  • Sending requests from 8081 to app1 and 8082 in app2

Getting JBoss to listen on multiple ports

It is easy.

Add lines like these to $JBOSS_HOME/server/default/deploy/jbossweb.sar/server.xml

 <!-- A HTTP/1.1 Connector on port 8081 --> <Connector protocol="HTTP/1.1" port="8081" address="${jboss.bind.address}" redirectPort="${jboss.web.https.port}" /> <!-- A HTTP/1.1 Connector on port 8082 --> <Connector protocol="HTTP/1.1" port="8082" address="${jboss.bind.address}" redirectPort="${jboss.web.https.port}" /> 

Observe the following log messages when loading the server:

 11:56:23,639 INFO [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8081 11:56:23,640 INFO [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8082 

Note. If you want to do this “correctly”, you must use placeholders instead of hard-coded numbers and edit $JBOSS_HOME/server/default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml to define them. But, if you do not need to manage ports through the management interface, this will be redundant.

Send requests to port 8081 in app1 and port 8082 in application2

This is much more complicated. JBoss uses its own Tomcat engine, which does not support multiple webapp roots (the appBase attribute does not work). Thus, it is not possible to configure two different directories for your connectors. You can add virtual hosts and use jboss-web.xml in each application to configure which vhost it responds to, but that means you need to use different names in the client URLs.

Here you have two options.

Option 1: JBoss RewriteValve

Add this to the Host configuration item (before other valve definitions) in $JBOSS_HOME/server/default/deploy/jbossweb.sar/server.xml

  <Valve className="org.jboss.web.rewrite.RewriteValve" /> 

Create the file $JBOSS_HOME/server/default/conf/jboss.web/localhost/rewrite.properties with the following contents:

 RewriteCond %{SERVER_PORT} =8081 RewriteRule ^/(.*)$ /app1/$1 [L] RewriteCond %{SERVER_PORT} =8082 RewriteRule ^/(.*)$ /app2/$1 [L] 

Note. You may need to create the directory $JBOSS_HOME/server/default/conf/jboss.web/localhost/ , by default it does not exist.

rewrite.properties : The location of rewrite.properties depends on the location of the Valve tag in server.xml . Most intuitive layout with other Valve elements. However, this is true under Engine . In this case, the rewrite.properties file should be moved up one directory.

Option 2: servlet filter in the context of ROOT

Expand the servlet filter to $JBOSS_HOME/server/default/deploy/ROOT.war/ , which sends requests based on the incoming port. You can either run your own custom filter implementation, or use UrlRewriteFilter with a configuration that looks like this:

 <rule> <condition type="port">8081</condition> <from>/(.*)</from> <to context="app1">/$1</to> </rule> <rule> <condition type="port">8082</condition> <from>/(.*)</from> <to context="app2">/$1</to> </rule> 

See also:

EDIT: Given the complexity of the JBoss configuration, you can also choose the Apache reverse proxy server located in front of the application server.

+7
source share

The JBoss AS7 configuration version discussed in the answer for AS6 with multiple http connectors and a rewrite valve.

 --- standalone/configuration/standalone.xml.orig 1970-01-01 00:00:00.000000000 -0100 +++ standalone/configuration/standalone.xml 1970-01-01 00:00:00.000000000 -0100 @@ -257,9 +257,17 @@ </subsystem> <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false"> <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/> + <connector name="http1" protocol="HTTP/1.1" scheme="http" socket-binding="http1"/> + <connector name="http2" protocol="HTTP/1.1" scheme="http" socket-binding="http2"/> <virtual-server name="default-host" enable-welcome-root="true"> <alias name="localhost"/> <alias name="example.com"/> + <rewrite pattern="^/(.*)$" substitution="/app1/$1" flags="L"> + <condition test="%{SERVER_PORT}" pattern="=8081" flags=","/> + </rewrite> + <rewrite pattern="^/(.*)$" substitution="/app2/$1" flags="L"> + <condition test="%{SERVER_PORT}" pattern="=8082" flags=","/> + </rewrite> </virtual-server> </subsystem> <subsystem xmlns="urn:jboss:domain:webservices:1.1"> @@ -293,6 +301,8 @@ <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/> <socket-binding name="ajp" port="8009"/> <socket-binding name="http" port="8080"/> + <socket-binding name="http1" port="8081"/> + <socket-binding name="http2" port="8082"/> <socket-binding name="https" port="8443"/> <socket-binding name="osgi-http" interface="management" port="8090"/> <socket-binding name="remoting" port="4447"/> 

See also:

+3
source share

All Articles