如何在不同端口后面的单个JBoss AS 6实例上运行不同的应用程序? [英] How to run different apps on single JBoss AS 6 instance behind different ports?
问题描述
我来自此这样,但是我的情况不是在Tomcat上,而是在JBoss EAP 6上.因此,假设我在JBoss AS 6上运行了两个Web应用程序app1和app2:
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
http://localhost:8080/app2
上的- app1 on
http://localhost:8080/app1
- app2 on
http://localhost:8080/app2
但是我想配置Tomcat,以便它们在根上下文中在单独的端口后面运行:
However I want to configure Tomcat so that they run in root context behind separate ports:
-
http://localhost:8081
上的app1
- app2
http://localhost:8082
上的- app1 on
http://localhost:8081
- app2 on
http://localhost:8082
如何在JBoss EAP 6上实现它?请注意此答案不适用于我它针对JBoss 5.
How can I make it on JBoss EAP 6? Note this answer doesn't work for me as it targets JBoss 5.
推荐答案
这些说明适用于原始问题所要求的JBoss AS6. AS7具有不同的配置文件语法.
These instructions are for JBoss AS6 as requested in the original question. AS7 has different configuration file syntax.
您的问题分为两个部分:
Your problem has two parts:
- 让JBoss在多个端口上监听
- 将请求发送到app1的8081和将app2发送到8082
让JBoss在多个端口上监听
这很容易.
Getting JBoss to listen on multiple ports
This one is easy.
将这样的行添加到$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 messages in the log when server boots up:
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
注意:如果要正确"执行此操作,则应使用占位符而不是硬编码数字,然后编辑$JBOSS_HOME/server/default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml
来定义它们.但是,除非您需要通过管理UI来管理端口,否则这将是一个过大的杀伤力.
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.
这要困难得多. JBoss使用其自己的Tomcat引擎,该引擎不支持多个webapp根目录(appBase属性不起作用).因此,不可能为连接器配置两个不同的目录.可以添加虚拟主机并在每个应用程序中使用jboss-web.xml
来配置它响应的虚拟主机,但这意味着您必须在客户端URL中使用不同的名称.
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.
您在这里有两个选择.
将此添加到$JBOSS_HOME/server/default/deploy/jbossweb.sar/server.xml
中的Host
配置元素中(在其他阀定义之前)
Add this to Host
configuration element (before other valve definitions) in $JBOSS_HOME/server/default/deploy/jbossweb.sar/server.xml
<Valve className="org.jboss.web.rewrite.RewriteValve" />
创建具有以下内容的文件$JBOSS_HOME/server/default/conf/jboss.web/localhost/rewrite.properties
:
Create a 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]
注意:您可能需要创建$JBOSS_HOME/server/default/conf/jboss.web/localhost/
目录,默认情况下该目录不存在.
Note: You may need to create the $JBOSS_HOME/server/default/conf/jboss.web/localhost/
directory, it does not exist by default.
注2:rewrite.properties
的位置取决于Valve
标记在server.xml
中的位置.最直观的位置是与其他Valve
元素一起使用.但是,它也直接在Engine
下有效.在这种情况下,rewrite.properties
文件需要上移一个目录.
Note2: Location of the rewrite.properties
depends on the placement of the Valve
tag in server.xml
. The most intuitive placement is with other Valve
elements. However it is valid directly under Engine
as well. In this case rewrite.properties
file needs to be moved up one directory.
将servlet筛选器部署到$JBOSS_HOME/server/default/deploy/ROOT.war/
,该筛选器根据传入端口调度请求.您可以推出自己的自定义过滤器实现,也可以使用如下配置的 UrlRewriteFilter :>
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:
<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>
另请参阅:
- https://community.jboss.org/wiki/VirtualHostsWithJBossAS
- http://docs.jboss.org/jbossweb/3.0.x /rewrite.html
- 如何在Java中使用Servlet过滤器来更改传入的Servlet请求网址?
- https://community.jboss.org/wiki/VirtualHostsWithJBossAS
- http://docs.jboss.org/jbossweb/3.0.x/rewrite.html
- How to use a servlet filter in Java to change an incoming servlet request url?
考虑到JBoss配置的复杂性,您还可以选择位于应用程序服务器前面的基于Apache的反向代理.
Given the complexity of JBoss configuration you may also opt for an Apache based reverse proxy that sits in front of the app server.
这篇关于如何在不同端口后面的单个JBoss AS 6实例上运行不同的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!