【问题标题】:http to https conditional redirect in jboss/wildflyjboss/wildfly 中的 http 到 https 条件重定向
【发布时间】:2019-09-20 20:51:53
【问题描述】:

JBoss/Wildfly => 独立的.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>

编辑

代理服务器转发 80 -> 8080。(即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)"/>

谢谢

【问题讨论】:

    标签: java web https jboss wildfly


    【解决方案1】:

    终于解决了

    <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 -> 不重定向

    http://xx.example.com -> 重定向到https://xx.example.com

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-14
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 2019-07-12
      • 2014-10-26
      • 1970-01-01
      • 2016-01-04
      相关资源
      最近更新 更多