HAProxy重定向方案无法按文档记录

时间:2014-01-27 21:07:31

标签: haproxy

我在LB后面运行HAProxy 1.4.24。 SSL在LB上终止。我想将http请求重定向到https。我有以下配置:

log         127.0.0.1 local2
chroot      /var/lib/haproxy
pidfile     /var/run/haproxy.pid
maxconn     4000
user        haproxy
group       haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats
defaults
  mode                    http
  log                     global
  option                  httplog
  option                  dontlognull
  option http-server-close
  option forwardfor       except 127.0.0.0/8
  option                  redispatch
  retries                 3
  timeout http-request    10s
  timeout queue           1m
  timeout connect         10s
  timeout client          1m
  timeout server          1m
  timeout http-keep-alive 10s
  timeout check           10s
  maxconn                 3000

frontend  httpIn *:7258
  maxconn             100000
  option forwardfor   header x-forwarded-for
  acl is_http hdr(X-Forwarded-Proto) http
  redirect scheme https code 301 if is_http
  default_backend             app

backend app
 balance     roundrobin
 cookie      LBSTICKY insert indirect nocache httponly secure maxlife 8h
 server  app1 10.10.10.10:8080 cookie app1
 server  app2 10.10.10.11:8080 cookie app2

我的问题是行

redirect scheme https code 301 if is_http

在运行haproxy -f /etc/haproxy/haproxy.cfg -c时生成以下错误:

[ALERT] 026/210541 (8482) : parsing [/etc/haproxy/haproxy.cfg:67] : 'redirect' expects 'code', 'prefix', 'location', 'set-cookie', 'clear-cookie', 'drop-query' or 'append-slash' (was 'scheme').`

我重新检查了说我正在使用正确的重定向语法的文档。有什么想法吗?

2 个答案:

答案 0 :(得分:4)

redirect scheme确实在HAProxy 1.4.24中不可用。目前,它可用于HAProxy 1.5-dev13及更高版本以及HAProxy 1.4.25及更高版本,包括haproxy-1.4 master

您查看的文档可能是当前从1.4版本生成的by Cyril Bonté,而不是1.4.24版本。

因此,您可以升级到其中一个指定版本或解决限制。常见的解决方法是使用redirect prefix这样的

redirect prefix https://domain.com if is_http { hdr(host) -i domain.com }

必须针对您希望重定向发生的每个主机名枚举此规则。

答案 1 :(得分:3)

此选项适用于HAProxy 1.5 ... 为此,您必须在1.4分支中使用重定向位置。

巴普蒂斯特

相关问题