Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于HTTP但不用于WebSocket的HAProxy SSL重定向_Ssl_Websocket_Port_Haproxy - Fatal编程技术网

用于HTTP但不用于WebSocket的HAProxy SSL重定向

用于HTTP但不用于WebSocket的HAProxy SSL重定向,ssl,websocket,port,haproxy,Ssl,Websocket,Port,Haproxy,我有HAProxy作为一个负载均衡器和动态重定向器连接到我的webserver和websocket服务器,这样它们就可以在同一个端口上运行。我的web套接字服务器需要在ha代理上进行SSL终止 我想配置HAProxy,以便将http流量重定向到https,但WebSocket在bot端口80和443(ws和wss)上工作。这可能吗 我当前的配置是: global maxconn 50000 user root group root stats socket /tmp/haproxy n

我有HAProxy作为一个负载均衡器和动态重定向器连接到我的webserver和websocket服务器,这样它们就可以在同一个端口上运行。我的web套接字服务器需要在ha代理上进行SSL终止

我想配置HAProxy,以便将http流量重定向到https,但WebSocket在bot端口80和443(ws和wss)上工作。这可能吗

我当前的配置是:

global
 maxconn 50000
 user root
 group root
 stats socket /tmp/haproxy
 node lb1
 nbproc 1
 #daemon
 #debug

defaults
 log global
 retries 3
 option dontlog-normal
 timeout connect 10000ms
 timeout client 10000ms
 timeout server 10000ms
 timeout tunnel 24h
 maxconn 50000
 mode http
 option http-server-close


backend wwwServers
 mode http
 balance roundrobin
 option httpchk HEAD / HTTP/1.1
 server www1 127.0.0.1:1138 check

backend wsServers
 server ws1 127.0.0.1:1137 check

frontend  secured
 bind :443 ssl crt /cert/cert.pem
 reqadd X-Forwarded-Proto:\ https
 default_backend wwwServers

frontend unsecured
 bind :80
 acl is_websocket hdr(Upgrade) -i WebSocket
 use_backend wsServers if is_websocket
 redirect scheme https if !{ ssl_fc }
 default_backend wwwServers
但这会在升级之前重定向websocket连接,因为ha proxy在我运行它时会执行以下操作: 放置在“use_backend”规则之后的“redirect”规则仍将在之前处理

任何帮助都将不胜感激


谢谢,

解决方案如下:

frontend  secured
    bind :443 ssl crt /path/to/certificate.pem
    reqadd X-Forwarded-Proto:\ https
    acl is_websocket hdr(Upgrade) -i WebSocket
    use_backend wsServers if is_websocket
    default_backend wwwServers
frontend unsecured
    bind :81,:80
    acl is_websocket hdr(Upgrade) -i WebSocket
    redirect scheme https if !{ ssl_fc } !is_websocket
    use_backend wsServers if is_websocket
    default_backend wwwServers

如果建立了非ssl非websocket连接,它将被重定向。

解决方案如下:

frontend  secured
    bind :443 ssl crt /path/to/certificate.pem
    reqadd X-Forwarded-Proto:\ https
    acl is_websocket hdr(Upgrade) -i WebSocket
    use_backend wsServers if is_websocket
    default_backend wwwServers
frontend unsecured
    bind :81,:80
    acl is_websocket hdr(Upgrade) -i WebSocket
    redirect scheme https if !{ ssl_fc } !is_websocket
    use_backend wsServers if is_websocket
    default_backend wwwServers

如果建立了非ssl非websocket连接,则会重定向该连接。

我找到了一个解决方案,该解决方案使用的是仅通过重定向而非web套接字连接前端不安全绑定:81,:80 acl是\u websocket hdr(升级)-I websocket重定向方案https if!{ssl_fc}!is_websocket use_backend wsServers is_websocket default_backend WWWSServers如果您找到了解决方案,请将其作为答案发布,并将您的答案标记为正确,这样这个问题就不会继续显示为“打开”。我找到了一个解决方案,如果不是web套接字连接,只需重定向前端不安全绑定:81,:80 acl是\u websocket hdr(升级)-i websocket重定向方案https如果!{ssl_fc}!is_websocket use_backend wsServers如果is_websocket default_backend WWWSServers如果您找到了解决方案,请将其作为答案发布,并将您的答案标记为正确,以便此问题不会继续显示为“打开”。