后端的 HAProxy 重定向方案不起作用
HAProxy redirect scheme in backend not working
我有一个 haproxy 集群,它有两个用于 http 和 https 的前端以及许多使用 domain2backend 映射选择的后端。
某些后端只能通过 HTTPS 访问。
我尝试在这些后端中使用 redirect scheme https code 301 if !{ ssl_fc }
,但 haproxy 似乎忽略了它。我什至尝试简单地重定向(没有任何条件),但 haproxy 忽略了后端部分的重定向。
配置摘录:
global
maxconn 1024
debug
log localhost local0 debug
tune.ssl.default-dh-param 2048
defaults
balance roundrobin
maxconn 32
log global
monitor-uri /haproxy_test
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:8080
mode http
option httplog
option forwardfor
use_backend %[req.hdr(host),lower,map_dom(./etc/domain2backend.map)]
frontend https-in
bind *:4443 ssl crt ./etc/ssl
mode http
option httplog
option forwardfor
http-request add-header X-Proto https if { ssl_fc }
use_backend %[req.hdr(host),lower,map_dom(./etc/domain2backend.map)]
backend app1_www
redirect scheme https if !{ ssl_fc }
server localhost:3000 127.0.0.1:3000 check
backend app2_www
redirect scheme https
server localhost:3000 127.0.0.1:3000 check
app1_www 和 app2_www 重定向都不起作用。
我正在使用 HA-Proxy 版本 1.7.3 2017/02/28
经过多次尝试并感谢 http://discourse.haproxy.org 的热心社区,我找到了解决方案:
需要在后端指定 mode http
以允许重定向工作。
变量 ssl_fc 在后端可用,因此可以像以下代码示例一样使用条件 if !{ ssl_fc}
:
backend app1_www
mode http
redirect scheme https if !{ ssl_fc }
server localhost:3000 127.0.0.1:3000 check
我有一个 haproxy 集群,它有两个用于 http 和 https 的前端以及许多使用 domain2backend 映射选择的后端。
某些后端只能通过 HTTPS 访问。
我尝试在这些后端中使用 redirect scheme https code 301 if !{ ssl_fc }
,但 haproxy 似乎忽略了它。我什至尝试简单地重定向(没有任何条件),但 haproxy 忽略了后端部分的重定向。
配置摘录:
global
maxconn 1024
debug
log localhost local0 debug
tune.ssl.default-dh-param 2048
defaults
balance roundrobin
maxconn 32
log global
monitor-uri /haproxy_test
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:8080
mode http
option httplog
option forwardfor
use_backend %[req.hdr(host),lower,map_dom(./etc/domain2backend.map)]
frontend https-in
bind *:4443 ssl crt ./etc/ssl
mode http
option httplog
option forwardfor
http-request add-header X-Proto https if { ssl_fc }
use_backend %[req.hdr(host),lower,map_dom(./etc/domain2backend.map)]
backend app1_www
redirect scheme https if !{ ssl_fc }
server localhost:3000 127.0.0.1:3000 check
backend app2_www
redirect scheme https
server localhost:3000 127.0.0.1:3000 check
app1_www 和 app2_www 重定向都不起作用。
我正在使用 HA-Proxy 版本 1.7.3 2017/02/28
经过多次尝试并感谢 http://discourse.haproxy.org 的热心社区,我找到了解决方案:
需要在后端指定 mode http
以允许重定向工作。
变量 ssl_fc 在后端可用,因此可以像以下代码示例一样使用条件 if !{ ssl_fc}
:
backend app1_www
mode http
redirect scheme https if !{ ssl_fc }
server localhost:3000 127.0.0.1:3000 check