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

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

问题描述

这是我的standalone-full.xml配置,配置了ssl

安全领域。

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

      <security-realm name="SslRealm">
            <server-identities>
            <ssl>
            <keystore path="D:\ncm.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

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

推荐答案

重写规则可用于重定向用户。在下层子系统(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来使重定向友好并保留用户的原始请求网址路径。

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)")

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

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