开发者社区> 问答> 正文

haproxy1.4.22请求头http1.1响应头http1.0 400 请求报错 

近来折腾haproxy,测试中发现我使用IE和curl发送请求头中为http1.1,但是haproxy的响应头是http1.0。

后来尝试1.4.22,1.4.21,1.4.19都相同效果。

不知道大家有没有遇到过这状况,怎么解决的。

如下:

# curl  http://10.10.77.67/car/120/32/65/Img1646532_120.jpg  -H host:m2.auto.it.cn  -o /dev/null -v

  • About to connect() to 10.10.77.67 port 80 (#0)

*   Trying 10.10.77.67... connected

  • Connected to 10.10.77.67 (10.10.77.67) port 80 (#0)

> GET /car/120/32/65/Img1646532_120.jpg HTTP/1.1

> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2

> Accept: /

> host:m2.auto.it.cn

>

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* HTTP 1.0, assume close after body

< HTTP/1.0 200 OK

< Server: nginx/0.8.55

< Date: Thu, 18 Oct 2012 09:04:20 GMT

< Content-Type: image/jpeg

< Content-Length: 4634

< Last-Modified: Wed, 25 Jul 2012 02:35:21 GMT

< Expires: Sun, 16 Oct 2022 09:04:20 GMT

< Cache-Control: max-age=315360000

< Accept-Ranges: bytes

< Age: 67409

< X-Cache: HIT from 106_213.auto.it.cn

< Via: 1.1 106_213.auto.it.cn:81 (squid/2.7.STABLE9)

< Connection: close

<

{ [data not shown]

100  4634  100  4634    0     0  1216k      0 --:--:-- --:--:-- --:--:-- 4525k* Closing connection #0

详细配置文件如下:

# grep -v ^'#' haproxy.cfg                  

global

    log    127.0.0.1 local3 info

    maxconn     8000

    ulimit-n 16014

    user  haproxy

    group haproxy

    chroot    /opt/haproxy1.4.22/

    pidfile /opt/haproxy1.4.22/logs/haproxy.pid

    nbproc 1    

    daemon

defaults

    mode http

    log global

    option httplog

    timeout connect 10s

    timeout client  10s

    timeout server  10s

    timeout check   2s

listen .auto.it.cn

    bind *:80

    log global

    option httplog

    monitor-net 192.168.106.0/24

    monitor-uri /haproxy.test

    balance   uri

    log    127.0.0.1 local0 debug

    hash-type consistent  

    server cache2 192.168.106.109:81 check inter 1500 rise 3 fall 3 weight 12

    server cache3 192.168.106.213:81 check inter 1500 rise 3 fall 3 weight 12

    http-check send-state

    fullconn 6000

    retries    3

    option redispatch

    option httpchk GET /flag.txt  HTTP/1.0\nHost:\ m1.auto.it.cn

    http-check expect status 200

listen haproxystat

    bind  *:6501

    stats enable

    stats uri   /haproxy-stats  

    stats realm Haproxy/Statistics

    stats auth  admin:admin

    stats hide-version

展开
收起
kun坤 2020-05-29 17:06:37 922 0
1 条回答
写回答
取消 提交回答
  • haproxy 不支持 HTTP/1.1 吧?

    ######

    引用来自“红薯”的答案

    haproxy 不支持 HTTP/1.1 吧?
    谢谢红薯。 我的haproxy后端是squid,抓包发现squid请求其后端的nginx源服务器是http1.0的头,从而其后端返回给squid的响应头也是http1.0。squid将该http1.0的响应返回给了haproxy,haproxy将响应头为http1.0的结果响应给客户端。 将squid去掉,haproxy后端直连nginx后,haproxy发送给nginx http1.1的头,同时接收到nginx1.1的响应头,然后将http1.1的响应返回给客户端。。 是测试中使用的squid没支持http1.1导致的。 ######我印象中这两款软件都不支持 http/1.1 的,不知道现在的版本如何######

    引用来自“stormcc”的答案

    引用来自“红薯”的答案

    haproxy 不支持 HTTP/1.1 吧?
    谢谢红薯。 我的haproxy后端是squid,抓包发现squid请求其后端的nginx源服务器是http1.0的头,从而其后端返回给squid的响应头也是http1.0。squid将该http1.0的响应返回给了haproxy,haproxy将响应头为http1.0的结果响应给客户端。 将squid去掉,haproxy后端直连nginx后,haproxy发送给nginx http1.1的头,同时接收到nginx1.1的响应头,然后将http1.1的响应返回给客户端。。 是测试中使用的squid没支持http1.1导致的。
    我用的是当前最新版1.4.22,今年8月14号发布的。目前看这个版本是支持的。 ######那 squid 呢? squid 支持吗?######

    引用来自“stormcc”的答案

    引用来自“stormcc”的答案

    引用来自“红薯”的答案

    haproxy 不支持 HTTP/1.1 吧?
    谢谢红薯。 我的haproxy后端是squid,抓包发现squid请求其后端的nginx源服务器是http1.0的头,从而其后端返回给squid的响应头也是http1.0。squid将该http1.0的响应返回给了haproxy,haproxy将响应头为http1.0的结果响应给客户端。 将squid去掉,haproxy后端直连nginx后,haproxy发送给nginx http1.1的头,同时接收到nginx1.1的响应头,然后将http1.1的响应返回给客户端。。 是测试中使用的squid没支持http1.1导致的。
    我用的是当前最新版1.4.22,今年8月14号发布的。目前看这个版本是支持的。
    我使用的squid2.7 stable9, 目前只2.7分支的最新版,2010年4月发布的,不支持。 不知道其他的版本如何 ######option http-pretend-keepalive option http-srv-kpa squid需要配置如下: pconn_timeout 60 seconds //该时间可调 client_persistent_connections on ######

    引用来自“zeroot”的答案

    option http-pretend-keepalive option http-srv-kpa squid需要配置如下: pconn_timeout 60 seconds //该时间可调 client_persistent_connections on 谢谢~ 不过尝试中发现1.4.22使用    option http-srv-kpa指令报错,配置到 listen上下文中 如下:     option http-pretend-keepalive     option http-srv-kpa ## stat instance listen haproxystat     bind  *:6501     stats enable     stats uri   /haproxy-stats     stats realm Haproxy/Statistics     stats auth  admin:admin     stats hide-version 报错如下: [@zjm_106_213 ~]#  [@zjm_106_213 ~]# service haproxy restart                     [ALERT] 303/182241 (5891) : parsing [/opt/haproxy1.4.22//etc/haproxy.cfg:46] : unknown option 'http-srv-kpa'. [ALERT] 303/182241 (5891) : Error(s) found in configuration file : /opt/haproxy1.4.22//etc/haproxy.cfg [ALERT] 303/182241 (5891) : Fatal errors found in configuration. Errors found in configuration file, check it with 'haproxy check'. [@zjm_106_213 ~]#  ######我就是1.4.22你位置写错了吧,官方文档也有这个参数的解释,怎么会么有呢######

    引用来自“zeroot”的答案

    我就是1.4.22你位置写错了吧,官方文档也有这个参数的解释,怎么会么有呢
    我看的 http://cbonte.github.com/haproxy-dconv/configuration-1.4.htmlhttp://haproxy.1wt.eu/download/1.4/doc/configuration.txt ######

    引用来自“zeroot”的答案

    我就是1.4.22你位置写错了吧,官方文档也有这个参数的解释,怎么会么有呢
    初用不熟悉,配置文件如下: [@zjm_106_213 etc]# cat haproxy.cfg |grep -v ^$ |grep -v '#'  global     log    127.0.0.1 local3 info     maxconn  7000     ulimit-n 16014     user  haproxy     group haproxy     chroot    /opt/haproxy1.4.22/     pidfile /opt/haproxy1.4.22/logs/haproxy.pid     nbproc 1         daemon defaults     mode http     log global     option httplog     timeout connect 10s     timeout client  10s     timeout server  10s     timeout check   2s listen .auto.itc.cn     bind *:80     log global     option httplog     no option httpclose     monitor-net 192.168.106.0/24     monitor-uri /haproxy.test     balance   uri     hash-type consistent       server cache1 192.168.106.3:80   check inter 1500 rise 3 fall 3 weight 6     http-check send-state     fullconn 6000     retries    3     option redispatch     option httpchk GET /flag.txt  HTTP/1.1\nHost:\ m1.auto.itc.cn     http-check expect status 200     option http-pretend-keepalive      option http-srv-kpa  listen haproxystat     bind  *:6501     stats enable     stats uri   /haproxy-stats       stats realm Haproxy/Statistics     stats auth  admin:admin     stats hide-version ######这个是要写在 defaults 下面的!不能写listen下面。看官方文档吧,写的很清楚的,别人都是根据自己翻译的你懂的。哈
    2020-05-29 17:07:04
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
阿里巴巴HTTP 2.0实践及无线通信协议的演进之路 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载