如何在 JBoss EAP 6.4 中将 http 重定向到 https?

How to redirect http to https in JBoss EAP 6.4?

这里是如何将 substitution 设置为任何地址,以便我可以在 AWS Application Load Balancer 中使用它。

<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https"  enable-lookups="false" secure="true" />
<virtual-server name="default-host" enable-welcome-root="true">
    <rewrite pattern="^/(.*)$" substitution="https://localhost:443/" flags="RL">
        <condition test="%{HTTPS}" pattern="off" />
    </rewrite>               
    <alias name="localhost"/>
    <alias name="example.com"/>
</virtual-server>

我想要

<rewrite pattern="^/(.*)$" substitution="https://%HOST_NAME%" flags="RL">
    <condition test="%{HTTPS}" pattern="off" />
</rewrite>

以下是在 EAP 6 中从 http 重定向到 https 的步骤,

redirect-port="443" 添加到 http 连接器,如下所示:

<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" redirect-port="443"/>

将 https 的套接字绑定更改为 443,如下所示:

<socket-binding name="https" port="443"/>

在 EAP 6 中配置 https 连接器,

 <connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" secure="true">
                <ssl name="ssl" key-alias="mykey" password="password" certificate-key-file="/path/to/keystore.jks"/>
        </connector>

编辑应用web.xml如下:-

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

    </web-app>

这对我有用(configruation/standalone-full.xml 中的更改):

        <filters>
            <rewrite name="http-to-https" target="https://${jboss.qualified.host.name}:8443%U" redirect="true"/>
        </filters>