24.8. Apache mod_proxy HTTP 连接器

Apache mod_proxy 是一个 HTTP 连接器,支持通过 AJP、HTTP 和 HTTPS 协议进行连接。mod_proxy 可以在负载均衡或非负载均衡的配置中配置,并且支持粘性会话的概念。

mod_proxy 模块要求 JBoss EAP 在 undertow 子系统中配置 HTTP、HTTPS 或 AJP 侦听器,具体取决于您计划使用的协议。

注意

mod_cluster 是比 mod_proxy 更为高级的负载平衡器,是推荐的 HTTP 连接器。mod_cluster 提供 mod_proxy 的所有功能,以及其他功能。与 JBoss EAP mod_cluster HTTP 连接器不同,Apache mod_proxy HTTP 连接器不知道服务器或服务器组上的部署状态,也无法适应其相应地发送工作的位置。

如需更多信息,请参阅 Apache mod_proxy 文档

24.8.1. 在 Apache HTTP 服务器中配置 mod_proxy

安装 JBoss Core Services Apache HTTP 服务器或使用 JBoss Web 服务器时已包含 mod_proxy 模块,并且默认加载。

注意

自 3.1.0 版开始,Apache HTTP 服务器不再通过 JBoss Web 服务器分发。

请参阅以下适当的部分来配置基本的负载平衡或非 负载平衡代理。这些步骤假定您已导航到 Apache HTTP 服务器的 httpd/ 目录,这些服务器将根据您的平台而有所不同。如需更多信息,请参阅 JBoss Core ServicesApache HTTP Server 安装指南中的平台安装说明。这些步骤还假定 JBoss EAP undertow 子系统中已配置了所需的 HTTP 侦听器。

注意

红帽客户还可以使用红帽客户门户网站中的负载平衡器配置工具为 mod_proxy 和其他连接器快速生成最佳配置模板。请注意,您必须登录才能访问此工具。

添加非负载平衡代理

将以下配置添加到您的 conf/httpd.conf 文件中,直接在您拥有的任何其他 <VirtualHost> 指令下。将值替换为适合您的设置的值。

<VirtualHost *:80>
# Your domain name
ServerName YOUR_DOMAIN_NAME

ProxyPreserveHost On

# The IP and port of JBoss
# These represent the default values, if your httpd is on the same host
# as your JBoss managed domain or server

ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

# The location of the HTML files, and access control information
DocumentRoot /var/www
<Directory /var/www>
Options -Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
添加负载平衡代理
注意

默认 Apache HTTP 服务器配置禁用 mod_proxy_balancer.so 模块,因为它与 mod_cluster 不兼容。要完成此任务,您需要加载此模块并禁用 mod_cluster 模块。

若要将 mod_proxy 用作负载平衡器并将工作发送到多个 JBoss EAP 实例,请将以下配置添加到您的 conf/httpd.conf 文件中:IP 地址示例为虚构。使用适合您的环境的值替换它们。

<Proxy balancer://mycluster>

Order deny,allow
Allow from all

# Add each JBoss Enterprise Application Server by IP address and port.
# If the route values are unique like this, one node will not fail over to the other.
BalancerMember http://192.168.1.1:8080 route=node1
BalancerMember http://192.168.1.2:8180 route=node2
</Proxy>

<VirtualHost *:80>
 # Your domain name
 ServerName YOUR_DOMAIN_NAME

 ProxyPreserveHost On
 ProxyPass / balancer://mycluster/

 # The location of the HTML files, and access control information DocumentRoot /var/www
 <Directory /var/www>
  Options -Indexes
  Order allow,deny
  Allow from all
 </Directory>

</VirtualHost>

以上示例都使用 HTTP 协议进行通信。如果载入适当的 mod_proxy 模块,您可以使用 AJP 或 HTTPS 协议。如需了解更多详细信息,请参阅 Apache mod_proxy 文档

启用粘滞会话

粘性会话意味着,如果某个客户端请求最初发送到特定的 JBoss EAP 工作程序,则以后的所有请求都将发送到同一工作程序,除非变得不可用。这几乎都是推荐的行为。

要为 mod_proxy 启用粘性会话,请将 stickysession 参数添加到 ProxyPass 语句中。

ProxyPass / balancer://mycluster stickysession=JSESSIONID

您可以为 ProxyPass 语句指定其他参数,如 lbmethodnofailover。有关可用参数的更多信息,请参阅 Apache mod_proxy 文档