Apache & JBoss 同时使用 80 端口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1357035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache & JBoss use port 80 at the same time
提问by Stella Peristeraki
I have both Apache 2 and JBoss 4.2.3 on the same machine and would like both of them to use port 80. There are several ways I see people doing this mod_jk, mod_proxy, but I'm not sure which one is the best.
我在同一台机器上同时安装了 Apache 2 和 JBoss 4.2.3,并希望它们都使用端口 80。我看到人们通过多种方式执行此 mod_jk、mod_proxy,但我不确定哪一种是最好的。
I don't need any load balancing, but I do need HTTPS.
我不需要任何负载平衡,但我确实需要 HTTPS。
回答by Lloyd Meinholz
You can't have two applications listening to the same tcp port (80) at the same time. You can use mod_jk to have http requests on port 80 routed from Apache server to the JBoss server. This is the method I am most familiar with and prefer. mod_proxy should also work, but I find that method a little more complicated.
您不能让两个应用程序同时侦听同一个 tcp 端口 (80)。您可以使用 mod_jk 将端口 80 上的 http 请求从 Apache 服务器路由到 JBoss 服务器。这是我最熟悉和最喜欢的方法。mod_proxy 也应该可以工作,但我发现这个方法有点复杂。
Configuring https on Apache is probably best dealt with as a separate topic. There are issues with purchasing a ssl certificate, creating a self-signed certificate, etc.
在 Apache 上配置 https 可能最好作为一个单独的主题来处理。购买 ssl 证书、创建自签名证书等存在问题。
There are two steps to accomplish configure mod_jk to route requests from the Apache server to the JBoss server:
有两个步骤来完成配置 mod_jk 以将请求从 Apache 服务器路由到 JBoss 服务器:
Configure the Apache web server to forward some requests to the JBoss server.
配置 Apache Web 服务器将一些请求转发到 JBoss 服务器。
The Apache configuration will vary depending on the distribution of Apache that you are using (windows, RHEL, debian, built from source, etc.) but the concepts should be similar for any Apache installation.
Apache 配置将根据您使用的 Apache 发行版(windows、RHEL、debian、从源代码构建等)而有所不同,但任何 Apache 安装的概念都应该是相似的。
You need to download mod_jk for your platform from the tomcat web site:
http://tomcat.apache.org/download-connectors.cgi
Your OS vendor may provide a binary for you, so check there first. You may also compile mod_jk yourself if you prefer.
您需要从 tomcat 网站下载适用于您平台的 mod_jk:
http: //tomcat.apache.org/download-connectors.cgi
您的操作系统供应商可能会为您提供二进制文件,因此请先检查那里。如果您愿意,也可以自己编译 mod_jk。
Copy the mod_jk binary (mod_jk.so for Linux/UNIX system, not sure about windows) into your Apache servers modules directory (this depends on the Apache distribution you are using).
将 mod_jk 二进制文件(Linux/UNIX 系统的 mod_jk.so,不确定 windows)复制到您的 Apache 服务器模块目录(这取决于您使用的 Apache 发行版)。
Add the equivalent directive to your Apache configuration:
将等效指令添加到您的 Apache 配置中:
LoadModule jk\_module /usr/lib/apache2/modules/mod\_jk.so
You should add two configuration files to the Apache configuration directory: mod_jk.conf and workers.properties. You should include mod_jk.conf from the main Apache configuration file:
您应该将两个配置文件添加到 Apache 配置目录:mod_jk.conf 和 workers.properties。您应该从主 Apache 配置文件中包含 mod_jk.conf:
Include /etc/apache2/mod\_jk.conf
The workers.properties file is included by mod_jk.conf with the JkWorkersFile directive.
worker.properties 文件由 mod_jk.conf 和 JkWorkersFile 指令一起包含。
More detailed settings for mod_jk.conf can be found at the tomcat documentation page:
http://tomcat.apache.org/connectors-doc/reference/apache.html
更详细的 mod_jk.conf 设置可以在 tomcat 文档页面找到:http:
//tomcat.apache.org/connectors-doc/reference/apache.html
The important directives are:
JkWorkersFile (specifies where the workers.properties file lives)
JkMount (mount point for mapping of URI to tomcat worker)
重要的指令是:
JkWorkersFile(指定 workers.properties 文件所在的位置)
JkMount(用于将 URI 映射到 tomcat worker 的挂载点)
An example:
一个例子:
JkWorkersFile /etc/apache2/workers.properties<br>
JkMount /examples/* myworker<br>
JkMount /examples myworker
These directives map the /examples and /examples/ URI to the myworker tomcat worker.
这些指令将 /examples 和 /examples/ URI 映射到 myworker tomcat worker。
Conceptually you can think of a worker as representing a tomcat or JBoss instance and the mount as a way of mapping a URI to a worker. This way of representing things allows one Apache server to be the front end for several tomcat or JBoss servers. This can be handy if you have only one IP address you can use but wish to run several application servers behind one Apache server.
从概念上讲,您可以将工作人员视为代表 tomcat 或 JBoss 实例,而将挂载视为将 URI 映射到工作人员的一种方式。这种表示事物的方式允许一个 Apache 服务器作为多个 tomcat 或 JBoss 服务器的前端。如果您只有一个 IP 地址可以使用,但希望在一台 Apache 服务器后面运行多个应用程序服务器,这会很方便。
The workers.properties files describes the tomcat or JBoss server(s) that the Apache server will connect to. Important entries in this file are:
worker.properties 文件描述了 Apache 服务器将连接到的 tomcat 或 JBoss 服务器。该文件中的重要条目是:
worker.list=myworker<br>
worker.tomcat.type=ajp13<br>
worker.tomcat.host=localhost<br>
worker.tomcat.port=8009
There are other worker properties that can be found in the tomcat documentation page for the workers.properties file:
http://tomcat.apache.org/connectors-doc/reference/workers.html
在 worker.properties 文件的 tomcat 文档页面中可以找到其他工作器属性:http:
//tomcat.apache.org/connectors-doc/reference/workers.html
Configure the JBoss server to accept connections from the Apache server
配置 JBoss 服务器以接受来自 Apache 服务器的连接
The JBoss server is configured to accept mod_jk connections on port 8009 (the default ajp port) out of the box, but it is good to know where to configure this in case you want to change any of this in the future.
JBoss 服务器被配置为开箱即用地接受端口 8009(默认的 ajp 端口)上的 mod_jk 连接,但最好知道在哪里配置它,以防您将来想更改其中的任何一个。
The configuration is in the tomcat based portion of the JBoss server located in ${JBOSS_SERVER_CONFIGURATION}/deploy/jbossweb.sar/server.xml. This is for JBoss AS 5.1.0.GA, previous versions are in a similar location. The mod_jk connector is configured in the Connector section for the AJP 1.3 protocol and looks like:
配置位于 ${JBOSS_SERVER_CONFIGURATION}/deploy/jbossweb.sar/server.xml 中的 JBoss 服务器的基于 tomcat 的部分。这是针对 JBoss AS 5.1.0.GA 的,以前的版本在类似的位置。mod_jk 连接器在连接器部分为 AJP 1.3 协议配置,看起来像:
<Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}" redirectPort="8443" />
The most common reason to modify this section is if you have multiple tomcat or JBoss servers connecting to apache via the AJP protocol, you can adjust the port number that the AJP connector will listens on so there are no conflicts.
修改本节最常见的原因是,如果您有多个 tomcat 或 JBoss 服务器通过 AJP 协议连接到 apache,您可以调整 AJP 连接器将侦听的端口号,以免发生冲突。

