我有一个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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5431 次 |
| 最近记录: |