配置 Haproxy 以允许 http CRUD(重写规则)

Configuring Haproxy to allow http CRUD (rewrite rules)

我正在使用 haproxy 进行负载平衡并获得我的 (RESTFUL)API 的高可用性,我面临的问题是:我无法将 REST 请求发送到 API。 我的意思是 haproxy 默认不支持 REST API,我想我应该配置一个 ACL 来让它工作,但我找不到任何关于配置 RESTFUL 支持和为 haproxy 启用 http 重写规则。

我的API基于laravel框架。

例如,如果我点击 192.168.1.139/login,我会收到 404 错误消息。唯一有效的路由是 /,它显示用户 "you are not logged in." 消息。

这是 haproxy 配置:

listen http_front
        bind *:80
        mode http
        stats enable
        stats uri /haproxy?stats
        option httpclose
        option forwardfor
        #acl api_exp hdr(host) -i domain_name.com
        #use_backend api_servers if api_exp
        default_backend api_servers

backend api_servers
        balance roundrobin
        server replica1 192.168.100.110:80 check
        server replica2 192.168.100.111:80 check

有点奇怪,但我已经用这个配置解决了我的问题:

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    retries 3
    option redispatch
    timeout connect  5000
    timeout client  100s
    timeout server  100s


listen ha-www
bind 0.0.0.0:80
    mode http
    stats enable
    stats uri /haproxy?stats
    stats realm Strictly\ Private
    balance roundrobin
    option httpclose
    option forwardfor
    server app-www-1 192.168.100.110:80 check
    server app-www-2 192.168.100.111:80 check