jboss/wildfly 中的 http 到 https 条件重定向

http to https conditional redirect in jboss/wildfly

JBoss/Wildfly => standalone.xml

仅当请求 url 包含域名时,才将 http 重定向到 https。如果从ip地址访问的网站不重定向。

http://x.x.x.x:8080 -> do not redirect

http://xx.example.com -> redirect to https://xx.example.com

我在 standalone.xml

中使用以下代码使用 http 到 https 重定向
<server name="default-server">
    <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
    <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
    <host name="default-host" alias="localhost">
        <filter-ref name="http-to-https" predicate="equals(%p,8080)"/>
    </host>
</server>
<filters>
    <rewrite name="http-to-https" target="https://%v%U%q" redirect="true"/>
</filters>

但在这种情况下,如果端口为 8080,则重定向所有来自 ip 或域名的请求。

http://x.x.x.x:8080 -> redirecting to https://x.x.x.x:8080

http://xx.example.com -> redirecting to https://xx.example.com

但是如果从ip请求我不重定向,只从域名重定向。

我使用 standalone.xml 中的以下代码使用 http 到 https 重定向。但在这两种情况下都不会重定向。

<server name="default-server">
    <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
    <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
    <host name="default-host" alias="localhost">
        <filter-ref name="http-to-https" predicate="regex(pattern='/http://(.*).example.com/g') and equals(%p,8080)"/>
    </host>
</server>
<filters>
    <rewrite name="http-to-https" target="https://%v%U%q" redirect="true"/>
</filters>

编辑

proxy server forward 80 -> 8080. (i.e http://xx.example.com -> http://xx.example.com:8080)

我也试过这个,但它在两种情况下都没有重定向。

<filter-ref name="http-to-https" predicate="regex(pattern='http://(.*).example.com', value=%U, full-match=false) and equals(%p,8080)"/>

谢谢

终于找到解决方案

<filter-ref name="http-to-https" predicate="regex(pattern='example', value=%v, full-match=false) and equals(%p,8080)"/>

http://x.x.x.x:8080 -> do not redirect

http://xx.example.com -> redirect to https://xx.example.com