将HAProxy websocket请求转发到https://www.websocket.org/echo.html

时间:2019-02-28 21:12:54

标签: websocket haproxy

我正尝试将我的haproxy负载均衡器(ec2 ubuntu 14.04)的websocket请求转发到https://www.websocket.org/echo.html进行测试。我在浏览器上看不到请求wss://echo.websocket.org和状态码为101的响应。这是我的haproxy.cfg。我将不胜感激。

defaults
  mode http
  log global
  option httplog
  option  http-server-close
  option  dontlognull
  option  redispatch
  option  contstats
  retries 3
  backlog 10000
  timeout client          25s
  timeout connect          5s
  timeout server          25s
  # timeout tunnel available in ALOHA 5.5 or HAProxy 1.5-dev10 and higher
  timeout tunnel        3600s
  timeout http-keep-alive  1s
  timeout http-request    15s
  timeout queue           30s
  timeout tarpit          60s
  default-server inter 3s rise 2 fall 3
  option forwardfor

frontend ft_web
  bind 0.0.0.0:80 name http
  maxconn 60000
  stats uri /haproxy?stats
  redirect scheme https if !{ ssl_fc }

## routing based on Host header
  acl host_ws hdr_beg(Host) -i ws.
  use_backend bk_ws if host_ws

## routing based on websocket protocol header
  acl hdr_connection_upgrade hdr(Connection)  -i upgrade
  acl hdr_upgrade_websocket  hdr(Upgrade)     -i websocket

  use_backend bk_ws if hdr_connection_upgrade hdr_upgrade_websocket
  default_backend bk_web

frontend ft_web_s
  mode http
  bind 0.0.0.0:443 ssl crt /etc/ssl/private/mydomain.pem
  maxconn 60000
  stats uri /haproxy?stats

## routing based on Host header
  acl host_ws hdr_beg(Host) -i ws.
  use_backend bk_ws if host_ws

## routing based on websocket protocol header
  acl hdr_connection_upgrade hdr(Connection)  -i upgrade
  acl hdr_upgrade_websocket  hdr(Upgrade)     -i websocket

  use_backend bk_ws if hdr_connection_upgrade hdr_upgrade_websocket
  default_backend bk_web

backend bk_web
  balance roundrobin
  option httpchk HEAD /
  server websrv1 172.20.132.23:8080 maxconn 100 weight 10 cookie websrv1 check
  server websrv2 172.20.133.236:8080 maxconn 100 weight 10 cookie websrv2 check
backend bk_ws
  balance roundrobin

## websocket protocol validation
  acl hdr_connection_upgrade hdr(Connection)                 -i upgrade
  acl hdr_upgrade_websocket  hdr(Upgrade)                    -i websocket
  acl hdr_websocket_key      hdr_cnt(Sec-WebSocket-Key)      eq 1
  acl hdr_websocket_version  hdr_cnt(Sec-WebSocket-Version)  eq 1
  http-request deny if ! hdr_connection_upgrade ! hdr_upgrade_websocket 
 ! hdr_websocket_key ! hdr_websocket_version

## ensure our application protocol name is valid
## (don't forget to update the list each time you publish new applications)
  acl ws_valid_protocol hdr(Sec-WebSocket-Protocol) echo-protocol http- 
request deny if ! ws_valid_protocol

## websocket health checking
 option httpchk GET / HTTP/1.1Host:\ http://websocket.org/echo.html:\ Upgrade\r\nUpgrade:\ websocket\r\nSec-WebSocket-Key:\ haproxy\r\nSec-WebSocket-Version:\ 13\r\nSec-WebSocket-Protocol:\ echo-protocol
http-check expect status 101

server websrv1 172.20.132.23:8080 maxconn 30000 weight 10 cookie websrv1 check
server websrv2 172.20.133.236:8080 maxconn 30000 weight 10 cookie websrv2 check

0 个答案:

没有答案
相关问题