如何在 HAProxy 中缓存内容

Jos*_*ose 3 high-availability haproxy

global
log /dev/log    local0
log /dev/log    local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon

# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private

# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
#  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3

defaults
log global
mode    http
option  httplog
option  dontlognull
    timeout connect 5000
    timeout client  50000
    timeout server  50000
    option redispatch
   errorfile 400 /etc/haproxy/errors/400.http
   errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

#
# Back-end definition.
#

listen appname testingcart.co.uk:80
    mode http
    stats enable
    stats uri /haproxy?stats
    balance source
    option httpclose
    option forwardfor

    cookie PHPSESSID prefix
    cookie SERVERID insert indirect nocache

    server web1 ip.address1:80 check cookie s2
    server web2 ip.address3:80 check cookie s3
        server web3 ip.address2:80 check cookie s4
Run Code Online (Sandbox Code Playgroud)

假设这是我的初始配置。我听说默认情况下 HAProxy 不缓存内容。如何在不使用 Varnish 的情况下启用它。

chi*_*cks 9

不要使用错误的工具

是一个很棒的工具。它不提供缓存。快速扫描精美文档可以验证这一点。除非你想打补丁,否则你haproxy需要使用一个工具来做你想做的事情。

不要制造不可能的问题

通过要求 haproxy 做一些它没有做的事情并排除似乎可以做你想做的事情的工具,你创造了一个不可能的情况。对此没有技术解决方案。不要做出让你陷入困境的选择。

尝试清漆或任何实际缓存的东西

如果你克服了这个问题,你可能会发现这个关于使用带有 haproxy 的清漆的教程很有用,或者单独尝试清漆。也许squid 或memcached 会更适合您的速度。

  • 这在当时是真实有效的。现在 [HAProxy 这样做](https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#cache)。 (3认同)
  • 截至 2020 年 11 月,HAProxy 表示他们不支持 HaProxy/Varnish 比较博客条目中的缓存:https://www.haproxy.com/blog/haproxy-and-varnish-comparison/ (2认同)