如何将 Apache 配置为 Apache Tomcat 服务器的反向代理

在为 Apache Tomcat 服务器选择代理解决方案时,有很多选择,Apache HTTPD、HAProxy 和 NGiNX 是目前最常用的一些开源解决方案。

在本快速教程中,我们将介绍如何将 Apache HTTPD 配置为 Apache Tomcat 服务器的反向代理。
Apache HTTPD 服务器将把所有来自 80 端口的流量重定向到 8080 端口上的 Apache Tomcat 服务器

要安装 Apache 服务器,请使用以下命令:

# yum install httpd # On centOS/RHEL
# apt install apache2 # On Ubuntu

在系统启动时启用并启动 Apache:

# sudo systemctl start httpd && sudo systemctl enable httpd # On centOS/RHEL
# sudo systemctl start apache2 && sudo systemctl enable apache2 # On Ubuntu

让我们创建一个名为 tomcat.conf 的新 Apache vhost 文件,如下所示,或者我们可以编辑默认的 Apache 配置文件

<virtualhost *:80>
        ServerName onitroad.local # YOUR DOMAIN NAME
        ServerAlias www.onitroad.local
        ServerAdmin jack@onitroad
        ProxyRequests Off
        ProxyPass/http://localhost:8080/
        ProxyPassReverse/http://localhost:8080/# YOUR TOMCAT IP ADDRESS
</virtualhost>

运行以下命令测试配置文件的语法有效性

# httpd -t # On CentOS/RHEL 
# apache2ctl configtest # On Ubuntu

最后,运行以下命令之一以重新加载新的 vhost 配置:

# httpd -k graceful # On CentOS/RHEL
# apache2ctl -k graceful # On Ubuntu

如果我们在 CentOS 7 或者 RHEL 7 上安装了 Apache 并且启用了 Selinux,我们需要执行以下命令:

# setsebool -P httpd_can_network_connect=1
日期:2020-06-02 22:18:51 来源:oir作者:oir