为什么websocket连接在几秒钟后关闭

时间:2016-10-26 12:14:11

标签: php amazon-web-services ssl websocket haproxy

我现在已经尝试解决这个问题,但没有结果。所以我们在aws负载均衡器后面有一个aws ec2实例,并且为负载均衡器分配了一个aws free ssl。在我们的ec2实例中,我们有一个apache web服务器监听端口1338和一个websocket服务器(使用Ratchet)监听端口8080.我们之间正在使用HAProxy和这个配置

global
    log     127.0.0.1   local0
    maxconn 10000
    user    haproxy
    group   haproxy
    daemon

defaults
        mode                    http
        log                     global
        option                  httplog
        retries                 3
        backlog                 10000
        timeout client          30s
        timeout connect         30s
        timeout server          30s
        timeout tunnel          3600s
        timeout http-keep-alive 1s
        timeout http-request    15s

frontend public
        bind            *:80
        acl             is_websocket hdr(Upgrade) -i WebSocket
        use_backend     ws if is_websocket #is_websocket_server
        default_backend www

backend ws
    option forwardfor # This sets X-Forwarded-For
        timeout queue 5000
        timeout server 5000
        timeout connect 5000
        server  ws1     127.0.0.1:8080

backend www
    timeout server  30s
        server  www1    127.0.0.1:1338

所以除了Web套接字服务器之外,一切似乎都在起作用。当我尝试连接时,连接成功,但在大约50-60秒后,连接关闭,就像用户离开页面一样。这只有在使用https时才会发生。问题是,在我们的httpd.conf中,我们有一个mod_rewrite,它将所有http连接重定向到https。

另一个问题是,我们有websocket php客户端脚本,我们用它来连接到websocket服务器,这样我们就可以从php脚本发送通知,但是当我没有时,客户端无法连接到服务器。使用主机127.0.0.1和端口8080.当在没有ssl和haproxy的情况下进行本地测试时,一切都运行良好。我无法弄清楚问题出在哪里。这是我的HAProxy配置还是我需要在aws loadbalancer中更改一些东西?

修改 所以这些是来自haproxy的日志。我刚注意到另一件事。我一直向套接字服务器发送消息,客户端没有断开连接,所以如果每隔30秒就一直向服务器发送虚假消息,一切似乎都正常工作,但我仍然无法理解为什么这样做问题仅在使用HTTPS

    Oct 26 16:49:31 localhost haproxy[7831]: 172.31.51.17:18222 [26/Oct/2016:16:49:31.913] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:49:35 localhost haproxy[7831]: 172.31.16.211:6536 [26/Oct/2016:16:49:35.312] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:49:41 localhost haproxy[7831]: 172.31.51.17:18227 [26/Oct/2016:16:49:41.913] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:49:42 localhost haproxy[7831]: 172.31.18.111:22978 [26/Oct/2016:16:49:42.769] public www/www1 0/0/0/126/126 302 1040 - - ---- 1/1/0/0/0 0/0 "GET / HTTP/1.1"
Oct 26 16:49:45 localhost haproxy[7831]: 172.31.16.211:6537 [26/Oct/2016:16:49:45.312] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:49:46 localhost haproxy[7831]: 172.31.62.174:22616 [26/Oct/2016:16:49:46.025] public www/www1 0/0/0/120/120 302 1038 - - ---- 1/1/0/0/0 0/0 "GET / HTTP/1.1"
Oct 26 16:49:51 localhost haproxy[7831]: 172.31.51.17:18230 [26/Oct/2016:16:49:51.913] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:49:55 localhost haproxy[7831]: 172.31.16.211:6540 [26/Oct/2016:16:49:55.311] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:01 localhost haproxy[7831]: 172.31.51.17:18236 [26/Oct/2016:16:50:01.913] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:05 localhost haproxy[7831]: 172.31.16.211:6545 [26/Oct/2016:16:50:05.312] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:11 localhost haproxy[7831]: 172.31.51.17:18240 [26/Oct/2016:16:50:11.913] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:12 localhost haproxy[7831]: 172.31.18.111:22992 [26/Oct/2016:16:50:12.791] public www/www1 0/0/0/124/124 302 1038 - - ---- 1/1/0/0/0 0/0 "GET / HTTP/1.1"
Oct 26 16:50:15 localhost haproxy[7831]: 172.31.16.211:6548 [26/Oct/2016:16:50:15.312] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:16 localhost haproxy[7831]: 172.31.62.174:22626 [26/Oct/2016:16:50:16.056] public www/www1 0/0/0/120/120 302 1034 - - ---- 1/1/0/0/0 0/0 "GET / HTTP/1.1"
Oct 26 16:50:21 localhost haproxy[7831]: 172.31.51.17:18241 [26/Oct/2016:16:50:21.913] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:25 localhost haproxy[7831]: 172.31.16.211:6551 [26/Oct/2016:16:50:25.311] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:25 localhost haproxy[7831]: 172.31.18.111:22952 [26/Oct/2016:16:49:23.912] public ws/ws1 750/0/0/65/61448 101 314 - - ---- 0/0/0/0/0 0/0 "GET /socket/ HTTP/1.1"
Oct 26 16:50:31 localhost haproxy[7831]: 172.31.51.17:18244 [26/Oct/2016:16:50:31.913] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:35 localhost haproxy[7831]: 172.31.16.211:6556 [26/Oct/2016:16:50:35.312] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:41 localhost haproxy[7831]: 172.31.51.17:18246 [26/Oct/2016:16:50:41.913] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:42 localhost haproxy[7831]: 172.31.18.111:22998 [26/Oct/2016:16:50:42.814] public www/www1 0/0/0/154/154 302 1034 - - ---- 0/0/0/0/0 0/0 "GET / HTTP/1.1"
Oct 26 16:50:45 localhost haproxy[7831]: 172.31.16.211:6557 [26/Oct/2016:16:50:45.312] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:46 localhost haproxy[7831]: 172.31.62.174:22632 [26/Oct/2016:16:50:46.087] public www/www1 0/0/0/132/133 302 1034 - - ---- 0/0/0/0/0 0/0 "GET / HTTP/1.1"
Oct 26 16:50:51 localhost haproxy[7831]: 172.31.51.17:18252 [26/Oct/2016:16:50:51.914] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "<BADREQ>"
Oct 26 16:50:55 localhost haproxy[7831]: 172.31.16.211:6560 [26/Oct/2016:16:50:55.312] public public/<NOSRV> -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "<BADREQ>"

0 个答案:

没有答案