在wildfly 10中将http请求重定向到https [英] Redirect http requests to https in wildfly 10

查看:25
本文介绍了在wildfly 10中将http请求重定向到https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我配置了 ssl 的独立完整.xml 配置
安全领域.

This is my standalone-full.xml configuration with ssl configured
security realm .

      <security-realm name="SslRealm">
            <server-identities>
            <ssl>
            <keystore path="D:
cm.keystore" alias="ncm" keystore-password="*****" />
            </ssl>
            </server-identities>
        </security-realm>

子系统

 <server name="default-server">
            <http-listener name="default" socket-binding="http" redirect-socket="https"/>
            <https-listener name="default-ssl" socket-binding="https" security-realm="SslRealm"/>
            <host name="default-host" alias="localhost">
                <location name="/" handler="welcome-content"/>
                <filter-ref name="server-header"/>
                <filter-ref name="x-powered-by-header"/>
            </host>
        </server>

套接字绑定

   <socket-binding name="http" port="${jboss.http.port:8080}"/>
    <socket-binding name="https" port="${jboss.https.port:8443}"/>

当用户点击https:///localhost:8443/myApp"http://localhost:8080/myApp" rel="noreferrer">http://localhost:8080/myApp

How to redirect to https:///localhost:8443/myApp when user hits http://localhost:8080/myApp

推荐答案

重写规则可用于重定向用户.在 undertow 子系统(standalone.xml 或 domain.xml)中,您需要创建一个新的重写过滤器,然后在新的 fitler-ref 中启用过滤器:

A rewrite rule can be used to redirect users. In the undertow subsystem (standalone.xml or domain.xml) you will need to create a new rewrite filter and then enable the filter in a new fitler-ref:

在过滤器部分创建新的重写过滤器.在下面的示例中,用户将被重定向到 https://myhostname:443/my-app.%U 是原始请求 URL 路径的占位符;您想使用 %U 使重定向友好并保留用户的原始请求 URL 路径.

Create the new rewrite filter in the filters section. In the example below, users will be redirected to https://myhostname:443/my-app. %U is a placeholder for the original request URL path; you want to use %U to make the redirect friendly and keep users' original request URL path.

<filters>
<rewrite name="http-to-https" redirect="true" target="https://myhostname:8443%U"/>
</filters>

然后,启用过滤器并在主机部分配置谓词.谓词是您配置重写过滤器适用于什么的地方.在下面的示例中,我们的重写过滤器仅适用于去往 8080 端口的请求.

Then, enable the filter and configure a predicate in the host section. The predicate is where you configure what the rewrite filter applies to. In the example below, our rewrite filter will only apply to requests going to port 8080.

    <server name="default-server">
        <host name="default-host" alias="localhost">
            ...
            <filter-ref name="http-to-https" predicate="equals(%p,8080)"/>

以下是针对上述相同配置更改的 JBoss CLI 步骤:

Here are the JBoss CLI steps for the same configuration changes above:

/subsystem=undertow/configuration=filter/rewrite=http-to-https:add(redirect="true",target="https://myhostname:8443%U")
/subsystem=undertow/server=default-server/host=default-host/filter-ref=http-to-https:add(predicate="equals(%p,8080)")

这篇关于在wildfly 10中将http请求重定向到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆