如何在不同端口后面的单个 JBoss AS 6 实例上运行不同的应用程序? [英] How to run different apps on single JBoss AS 6 instance behind different ports?

查看:25
本文介绍了如何在不同端口后面的单个 JBoss AS 6 实例上运行不同的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自这个SO 但是我的情况不是在 Tomcat 上,而是在 JBoss EAP 6 上.所以假设我有两个 Web 应用程序 app1 和 app2 在 JBoss AS 6 上运行:

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 在 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
  • http://localhost:8082
  • 上的 app2
  • 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.

你的问题有两部分:

  1. 让 JBoss 监听多个端口
  2. 向 8081 向 app1 和 8082 向 app2 发送请求

让 JBoss 监听多个端口

这个很简单.

将这样的行添加到 $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-s 中使用不同的名称.

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

 <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>

另见:

鉴于 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆