HAProxy的HTTP代理passtrough,而不是304重定向

问题描述 投票:1回答:2

我试图让nginx的直通,其中用户会看到我的网站的URL地址栏,但得到的所有内容,来自其他网站代理的等价物。

目前,下面的代码将用户重定向通过返回304,而不是代理所述流量EXAMPLE2。

我需要它与HTTP(不是TCP)工作,因为我需要以此为AB测试,我需要检查的cookie的一部分。请检查代码中的注释下面的什么,我试图做的。

defaults
        mode http
        log global
        option httplog
        log 127.0.0.1 local0
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms

listen  http
        bind 127.0.0.1:8080

        acl set_cookie path_beg /set-cookie

        use_backend b-backend if { req.cook(SITEID) -m beg b-backend }
        use_backend b-backend if set_cookie

        default_backend ab-split-backend

backend a-backend
        option forwardfor
        server example1 example1.com:443 check maxconn 3000 inter 30s

backend b-backend
        cookie SITEID insert
        option http_proxy
        # how do I get example2 to passtrough and not 304 redirect?
        server example2 example2.com:443 check maxconn 3000 inter 30s

backend ab-split-backend
        balance roundrobin
        cookie SITEID insert indirect nocache maxlife 48h

        # how do I get example2 to passtrough?
        server example2 example2.com:443 weight 50 cookie b-backend

        server example1 example1.com:443 weight 50 cookie a-backend

reverse-proxy haproxy
2个回答
2
投票

HTTP 304是不是一个真正的重定向,它是表示Not Modified告诉客户端,服务器将有一个200回应和服务的内容,但请求的资产没有改变空的响应,所以客户端可以只使用它已经缓存。

所以我不完全知道你看到的是不正确的行为。也就是说,你的请求可以通过就好被传递,和后端服务器可以正确地与304响应。

该服务器对与此代码基于请求头If-Modified-Since和/或If-None-Match提供的信息做出响应的决定。所以,如果你真的想禁用该缓存机制,并确保完整的200响应每一次,你可以指示HAProxy的删除从传入请求这些标题:

listen  http
        bind 127.0.0.1:8080

        acl set_cookie path_beg /set-cookie

        # Delete headers related to caching
        http-request del-header If-Modified-Since
        http-request del-header If-None-Match

        use_backend b-backend if { req.cook(SITEID) -m beg b-backend }
        use_backend b-backend if set_cookie

        default_backend ab-split-backend

0
投票

它看起来像你正在尝试做的是让你的系统免受试图通过通过SSL通过该案,用于测试目的,而不是做以明文评估。我会建议在看到HTTP请求重定向从下面我的配置片段也考虑HAProxy的方案。我还建议看到例如基于重定向的另一个实例,专门为口述位置,你不小心的解密方法的流量要保持加密状态的方式。

至于从其他位置代理的信息,为您最好的选择是使用CloudFlare的,特别是如果你正在寻找某种形式的安全性的DDoS /附加层。另一种方法是建立自己的自定义DDoS防御解决方案,这是一个重大的痛苦。

frontend ALL
 bind   *:80
 bind   *:443 alpn h2,http/1.1 ssl crt /etc/haproxy/certs/eduarmor.com.pem
 http-request redirect scheme https code 301 if !{ ssl_fc }
 http-request redirect code 301 location http://www.%[hdr(host)]%[capture.req.uri] if { hdr(Host) -i eduarmor.com }
 mode   http
© www.soinside.com 2019 - 2024. All rights reserved.