在 Apache for Wildfly 上重定向 Https 请求

Redireting Https requests on Apache for Wildfly

我正在使用 Apache 虚拟主机 运行 多个网站。我在前面使用 apache,这个 apache 正在将 url 请求重定向到 wildfly 服务器。

我的 Apache 配置对于使用以下代码的 http 请求工作正常

<VirtualHost *:80>
    ServerAdmin webmaster@mysitedemo.com
    ServerName mysitedemo.com
    ServerAlias www.mysitedemo.com
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
    ErrorLog "logs/mysitedemo-error_log"
    CustomLog "logs/mysitedemo-access_log" common
</VirtualHost>

现在我也想处理 Https 请求,我在 vhosts 文件中添加了以下代码

<VirtualHost *:443>
    ServerAdmin webmaster@mysitedemo.com
    ServerName mysitedemo.com
    ServerAlias www.mysitedemo.com
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / https://localhost:8443/
    ProxyPassReverse / https://localhost:8443/
    ErrorLog "logs/mysitedemo-error_log"
    CustomLog "logs/mysitedemo-access_log" common
</VirtualHost>

但它无法正常工作,出现以下错误

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@mysitedemo.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

我已经在 Wildfly 服务器上设置了 SSL。我还需要为 Apache 购买单独的 SSL 还是可以在 Apache 上使用相同的 SSL?如果是,请解释一下我该怎么做?

要从 https://siteA 重定向到 https://siteB,您需要先获得站点 A(当然还有站点 B)的证书,然后正确配置它。在您的情况下,您既没有配置证书,也没有在端口 443 上配置 https。相反,您只是将端口 443 配置为另一个 HTTP(但不是 HTTPS)服务器,这在尝试使用 HTTPS 访问它时当然会出错。

Redireting Https requests on Apache for Wildfly

如果有人用评论中的附加信息来扩充您问题中的信息,那么您会发现您实际上并没有 重定向 客户题。在重定向的情况下,服务器将告诉客户端请求不同的服务器。您在这里所做的是 forwarding,您的 Apache 用作反向代理并将请求从客户端转发到 Wildfly 服务器,并将 Wildfly 的响应发送回客户端。

由于在这种情况下,客户端仅直接与 Apache 服务器交互,如果客户端使用 HTTPS,则此 Apache 服务器将执行 TLS 握手。 这意味着 Apache 必须配置适当的证书并启用 SSL。 然后 Apache 将终止来自客户端的原始 HTTPS 连接。由于您已将 ProxyPass 配置为 HTTPS url,Apache 将与代理的 Wildfly 服务器建立另一个 HTTPS 连接。而且,从客户端的角度来看,Wildfly 服务器是否启用 HTTPS 并不重要——重要的是如何访问 Apache 服务器。