【问题标题】:Forcing HTTPS redirect on Wildfly 10.0 directs to https://localhost:8443在 Wildfly 10.0 上强制 HTTPS 重定向指向 https://localhost:8443
【发布时间】:2016-12-27 19:01:38
【问题描述】:

在安装 Bitnami Ubutnu Wildfly 10 时强制使用 HTTPS 非常困难。

HTTPS 运行良好(例如 https://example.com 运行良好)

我尝试了许多不同的方法,但都没有结果。以下是我所做工作的一些亮点:

我修改了我的 web.xml 以添加它(注意 MYWEBNAME 已替换为我的战争文件名):

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

我修改了/opt/bitnami/apache2/conf/bitnami/bitnami.conf(根据https://docs.bitnami.com/aws/components/apache/):

        <VirtualHost _default_:80>
              DocumentRoot /opt/bitnami/apache2/htdocs"
ADD:          RewriteEngine On
ADD:          RewriteCond %{HTTPS} !=on
ADD:          RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
          ...
        </VirtualHost>

我修改了standalone.xml

     <management-interfaces>
        <http-interface security-realm="ApplicationRealm" http-upgrade-enabled="true">
            <socket-binding https="management-https"/>
        </http-interface>
    </management-interfaces>

我修改了我的根 index.html 以重定向到:

<SCRIPT>document.location="https://example.com";</SCRIPT>

根据Wildfly 9 http to https,我试过这个:

    <http-interface security-realm="ManagementRealm" http-upgrade-enabled="true">
        <socket interface="management" secure-port="${jboss.management.http.port:9990}"/>
    </http-interface>

这导致了 503 错误和 wildfly 死机,所以我将其删除。

我现在拥有的是 http://example.com 重定向到 https://localhost:8443

所以我认为它很接近,我只是不知道如何让它重定向到https://example.com:8443

【问题讨论】:

  • 我使用以下命令将 8080 重定向到 8443:sudo iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 8443 不确定是否这样是正确的答案,所以我在这里记录下来,等待有人确认。
  • 你试过这个吗? stackoverflow.com/questions/43752067/…为我工作?

标签: https wildfly-10


【解决方案1】:

我没有使用 Apache 代理 Wildfly。但在我的设置中,端口 80 或 8080(http://example.comhttp://example.com:8080)上的所有请求都被重定向到端口 443(https://example.com)。 完成 iptables 将流量从 80 重定向到 8080 和 443 到 8443,然后 wildfly 将 CONFIDENTIAL 传输请求重定向到端口 443 而不是 8443。 看看有没有帮助:make wildfly listen on port 443 not 8443

顺便说一句,一旦重定向的责任在客户端,使用 javascript 或任何其他客户端脚本重定向到 SSL 是不够安全的。

【讨论】:

  • 如何制作 iptables?
  • iptabes 是 ubuntu 的内置防火墙。在我提供的链接中,显示了您可以在哪里编写 iptables 命令(即启动 init.d 脚本)。
【解决方案2】:

对于寻求解决方案的其他人,这里是我所做的总结 - 全部在一个地方。这是位于该线程中的链接的摘要,因此向那些回答该问题的作者致敬。功劳属于他们,这只是对我有用的总结。

1。添加 IPTABLES 路由规则,将端口 443 路由到 8443。

sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443

提示:要查看您已有的规则,请使用:

sudo iptables -t nat -L -n -v

2。在配置中添加一个重写过滤器和一个谓词。添加 sn-p 的第 10 行和第 24 行显示的条目。

<subsystem xmlns="urn:jboss:domain:undertow:3.0">
    <buffer-cache name="default"/>
    <server name="default-server">
        <http-listener name="default" socket-binding="http" redirect-socket="https"/>
        <https-listener name="default-ssl" security-realm="ApplicationRealm" socket-binding="https"/>
        <host name="default-host" default-web-module="YOURWARFILENAMEHERE.war" alias="localhost">
            <location name="/" handler="welcome-content"/>
            <filter-ref name="server-header"/>
            <filter-ref name="x-powered-by-header"/>
            <filter-ref name="http-to-https" predicate="equals(%p,8080)"/>
            <!-- ADD THE filter-ref ENTRY ABOVE -->
        </host>
    </server>
    <servlet-container name="default">
        <jsp-config/>
        <websockets/>
    </servlet-container>
    <handlers>
        <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
    </handlers>
    <filters>
        <response-header name="server-header" header-name="Server" header-value="WildFly/10"/>
        <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
        <rewrite name="http-to-https" redirect="true" target="https://DOMAINNAMEHERE:8443%U"/>
        <!-- ADD THE rewrite ENTRY ABOVE, BE SURE TO SUBSTITUTE YOUR DOMAIN NAME -->
    </filters>
</subsystem>

注意:我想知道使用步骤 1 中的命令添加 iptables 重新路由从 8080 到 8443 是否就足够了,并且消除了对步骤 2 的需要。但是步骤 2 对我有用,所以我选择了它。如果他们愿意,我将把这个选项留给读者。

3。修改standalone.xml 的管理接口部分。

<management-interfaces>
    <http-interface security-realm="ManagementRealm" http-upgrade-enabled="true">
        <socket-binding https="management-https"/>
    </http-interface>
</management-interfaces>

请注意,这取代了对 http 的绑定。另请注意,此步骤可能与 HTTP 到 HTTPS 的转发没有直接关系,而只是 HTTPS 设置中的一个步骤。

4。重新启动 Wildfly 实例。

【讨论】:

  • 不知道为什么有人反对这个答案。它奏效了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-14
  • 2018-02-01
  • 2013-06-29
  • 1970-01-01
  • 2014-10-26
  • 2021-05-02
  • 2020-05-28
相关资源
最近更新 更多