undertow-handlers.conf 中的规则将 HTTP 重定向到 HTTPS [英] Rule in undertow-handlers.conf to redirect HTTP to HTTPS

查看:78
本文介绍了undertow-handlers.conf 中的规则将 HTTP 重定向到 HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在负载均衡器后面有一个 Wildfly,它们之间的连接始终是 HTTP.客户端和负载均衡器之间的连接可以是 HTTP 或 HTTPS.

I have a Wildfly behind a load balancer, the connection between them is always HTTP. The connection between the client and the load balancer can be HTTP or HTTPS.

负载均衡器设置一个标头 (X-Forwarded-Proto) 来让 Wildfly 知道客户端正在使用哪种协议.

The load balancer sets a header (X-Forwarded-Proto) to let the Wildfly know which protocol the client is using.

考虑到上述所有条件,我正在尝试编写一个 Undertow 规则来重定向到 HTTPS.

I'm trying to write an Undertow rule to redirect to HTTPS taking into account all the conditions above.

这是我比较成功的尝试之一(此规则写在 undertow-handlers.conf 文件中,它是该文件中唯一的内容):

This is one of my more successful tries (this rule is written in the undertow-handlers.conf file and it's the only thing in that file):

regex('/(.*)') 和regex(pattern='http',value='%{i,X-Forwarded-Proto}',full-match=true)->重定向(https://server.com/${1})

regex('/(.*)') and regex(pattern='http',value='%{i,X-Forwarded-Proto}',full-match=true)-> redirect(https://server.com/${1})

当客户端尝试访问一个像:http://server.com/myapp 的 url 被重定向到 https://server.com,但路径/myapp 丢失.

When the client try to access an url like: http://server.com/myapp is redirected to https://server.com, but the path /myapp is missing.

如何修复我的 Undertow 规则以保留完整路径?

How can I fix my Undertow rule to keep the full path?

推荐答案

尝试:

equals('http', %{SCHEME}) -> redirect(https://server.com/%U)

equals('http', %{i,X-Forwarded-Proto}) -> redirect(https://server.com/%U)

取决于您是否在 HTTP 侦听器中启用了代理地址转发(如果您有 undertow 将自动处理 X-Forwarded-Proto,因此它会显示在 %{SCHEME} 下).

Depending on if you have enabled proxy-address-forwarding in the HTTP listener (if you have undertow will automatically handle the X-Forwarded-Proto so it shows up under %{SCHEME}).

这篇关于undertow-handlers.conf 中的规则将 HTTP 重定向到 HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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