使用 httpProxyRedirect 配置 Liberty

Configuring Liberty with httpProxyRedirect

我正在尝试将不安全端口上的流量重定向到安全端口,如下所述: https://www.ibm.com/support/knowledgecenter/en/SSD28V_9.0.0/com.ibm.websphere.liberty.autogen.core.doc/ae/rwlp_config_httpProxyRedirect.html

相反,两个端口都可用,我在日志中看不到任何内容。就好像根本没有配置 httpProxyRedirect 一样。

<?xml version="1.0" encoding="UTF-8"?>
<server description="CAST Liberty Server">
    <!-- Enable features -->
    <featureManager>
        <feature>webProfile-7.0</feature>
    </featureManager>

    <application id="app" context-root="/" type="war" location="${war.name}">
        <classloader apiTypeVisibility="spec, ibm-api, api, third-party" />
    </application>

    <httpProxyRedirect id="defaultHttpProxyRedirect" httpPort="${http.port}" httpsPort="${https.port}" />

    <keyStore id="defaultKeyStore" password="pass" />
    <httpEndpoint host="*" httpPort="${http.port}" httpsPort="${https.port}" id="defaultHttpEndpoint" />

    <applicationMonitor updateTrigger="mbean" />
</server>

您很可能缺少 web.xml 中的安全约束。此配置告诉服务器需要通过安全传输访问哪些 URL,然后将符合条件的请求从非安全端口重定向到安全端口。本教程可能会有所帮助:https://docs.oracle.com/cd/E19798-01/821-1841/bncbk/index.html

此外,请记住 server.xml 中的 httpProxyRedirect 配置用于在应用程序服务器前面有代理服务器时进行重定向。例如,您的代理服务器可能位于主 "www.ibm.com" 主机上 - 侦听 HTTP 端口 80 和 HTTPS 端口 443。但是该主机可能会将一些请求路由到其他主机上的 Liberty 应用程序服务器(例如 "app1host.internal.ibm.com") 监听不同的端口(即 HTTP 端口 9080 和 HTTPS 端口 9443)。在这种情况下,仅在 web.xml 中使用安全约束会尝试将 Liberty 服务器上的客户端请求从 9080 重定向到 9443,但在 www.ibm.com 主机上 - 没有任何内容在这些端口上侦听。在这种情况下,您应该像这样配置 httpProxyRedirect:

<httpProxyRedirect httpPort="80" httpsPort="443" host="www.ibm.com" />

通过配置,对安全 URL 的客户端 HTTP 请求将被重定向到端口 443 上的 www.ibm.com,代理服务器将请求转发到 app1host.internal.ibm.com 端口 9443 .

希望这对您有所帮助, 安迪

这是我在 web.xml 中使用的安全约束,它适用于 Tomcat 和 IBM Websphere 8.5.5.15:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Entire Application</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

注意:确保将其放在 <servlet-mapping> 之后。