在 Wildfly 10.0 上强制 HTTPS 重定向指向 https://localhost:8443
Forcing HTTPS redirect on Wildfly 10.0 directs to https://localhost:8443
我在 Bitnami Ubutnu Wildfly 10 安装上强制使用 HTTPS 时遇到了一个非常具有挑战性的时间。
HTTPS 运行良好(例如 https://example.com 运行良好)
我尝试了很多不同的方法,但都没有结果。以下是我所做工作的一些要点:
我修改了我的 web.xml 以添加此内容(注意我的网站名称已替换为我的 war 文件名):
<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}/ [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>
根据 ,我试过这个:
<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 redirecting to https://localhost:8443
所以我认为它很接近,我只是不知道如何让它重定向到 https://example.com:8443 而不是
我没有使用 Apache 代理 Wildfly。但在我的设置中,所有请求都在端口 80 或 8080 (http://example.com or http://example.com:8080) is redirected to port 443 (https://example.com) 上。
它已完成使 iptables 将流量从 80 重定向到 8080,将流量从 443 重定向到 8443,然后 wildfly 将 CONFIDENTIAL 传输请求重定向到端口 443 而不是 8443。
请看是否有帮助:make wildfly listen on port 443 not 8443
顺便说一句,一旦重定向的责任在客户端,使用javascript或任何其他客户端脚本重定向到 SSL 就不够安全。
对于正在寻找解决方案的其他人,这里是我所做工作的总结 - 所有这些都集中在一处。这是位于该线程中的链接的摘要,所以 h/t 给那些回答了问题的作者。功劳属于他们,这只是对我有用的总结。
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。添加一个 Rewrite Filter 和一个 Predicate 到配置中。添加代码段第 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 步对我有用,所以我继续它。如果他们愿意,我会在 reader 之前尝试该选项。
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 实例。
我在 Bitnami Ubutnu Wildfly 10 安装上强制使用 HTTPS 时遇到了一个非常具有挑战性的时间。
HTTPS 运行良好(例如 https://example.com 运行良好)
我尝试了很多不同的方法,但都没有结果。以下是我所做工作的一些要点:
我修改了我的 web.xml 以添加此内容(注意我的网站名称已替换为我的 war 文件名):
<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}/ [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>
根据 ,我试过这个:
<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 redirecting to https://localhost:8443
所以我认为它很接近,我只是不知道如何让它重定向到 https://example.com:8443 而不是
我没有使用 Apache 代理 Wildfly。但在我的设置中,所有请求都在端口 80 或 8080 (http://example.com or http://example.com:8080) is redirected to port 443 (https://example.com) 上。 它已完成使 iptables 将流量从 80 重定向到 8080,将流量从 443 重定向到 8443,然后 wildfly 将 CONFIDENTIAL 传输请求重定向到端口 443 而不是 8443。 请看是否有帮助:make wildfly listen on port 443 not 8443
顺便说一句,一旦重定向的责任在客户端,使用javascript或任何其他客户端脚本重定向到 SSL 就不够安全。
对于正在寻找解决方案的其他人,这里是我所做工作的总结 - 所有这些都集中在一处。这是位于该线程中的链接的摘要,所以 h/t 给那些回答了问题的作者。功劳属于他们,这只是对我有用的总结。
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。添加一个 Rewrite Filter 和一个 Predicate 到配置中。添加代码段第 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 步对我有用,所以我继续它。如果他们愿意,我会在 reader 之前尝试该选项。
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 实例。