title: Why websocket connection closes after few seconds
body: <p>Well i've been trying to figure out this issue for a while now, but with no results. So we have an aws ec2 instance behind the aws load balancer and an aws free ssl assigned to the load balancer. In our ec2 instance we have an apache web server listening or port 1338 and a websocket server (using Ratchet) listening on port 8080. Between we are using HAProxy with this configuration</p>
  
  <pre><code>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
  </code></pre>
  
  <p>So everything seems to be working, except for the web socket server. When I try to connect, the connection is successful, but after about 50-60 seconds, the connection is closed as if the user was left the page. And this occurs only when using https. The issue is, that in our httpd.conf we have a mod_rewrite which redirects all http connections to https. </p>
  
  <p>Another issue is, that we have websocket php client script, which we use to connect to the websocket server so we could send notifications from php scripts, but that client can't connect to the server when I'm using the host 127.0.0.1 and the port 8080. When testing locally without ssl and haproxy, everything is working great. I just can't figure out where the problem is. Is it my HAProxy configuration or I need to change something in the aws loadbalancer?</p>
  
  <p><strong>Edit</strong>
  So these are the logs from the haproxy. I just noticed another thing. I keep sending messages to the socket server, the client doesn't get disconnected, so if keep sending dummy messages to the server after every 30 seconds, everything seems to working correctly, but I still can't understand why this issue is only when using HTTPS</p>
  
  <pre><code>    Oct 26 16:49:31 localhost haproxy[7831]: 172.31.51.17:18222 [26/Oct/2016:16:49:31.913] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  Oct 26 16:49:35 localhost haproxy[7831]: 172.31.16.211:6536 [26/Oct/2016:16:49:35.312] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  Oct 26 16:49:41 localhost haproxy[7831]: 172.31.51.17:18227 [26/Oct/2016:16:49:41.913] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  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/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  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/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  Oct 26 16:49:55 localhost haproxy[7831]: 172.31.16.211:6540 [26/Oct/2016:16:49:55.311] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  Oct 26 16:50:01 localhost haproxy[7831]: 172.31.51.17:18236 [26/Oct/2016:16:50:01.913] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  Oct 26 16:50:05 localhost haproxy[7831]: 172.31.16.211:6545 [26/Oct/2016:16:50:05.312] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  Oct 26 16:50:11 localhost haproxy[7831]: 172.31.51.17:18240 [26/Oct/2016:16:50:11.913] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  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/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  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/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  Oct 26 16:50:25 localhost haproxy[7831]: 172.31.16.211:6551 [26/Oct/2016:16:50:25.311] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 1/1/0/0/0 0/0 "&lt;BADREQ&gt;"
  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/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "&lt;BADREQ&gt;"
  Oct 26 16:50:35 localhost haproxy[7831]: 172.31.16.211:6556 [26/Oct/2016:16:50:35.312] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "&lt;BADREQ&gt;"
  Oct 26 16:50:41 localhost haproxy[7831]: 172.31.51.17:18246 [26/Oct/2016:16:50:41.913] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "&lt;BADREQ&gt;"
  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/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "&lt;BADREQ&gt;"
  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/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "&lt;BADREQ&gt;"
  Oct 26 16:50:55 localhost haproxy[7831]: 172.31.16.211:6560 [26/Oct/2016:16:50:55.312] public public/&lt;NOSRV&gt; -1/-1/-1/-1/0 400 187 - - CR-- 0/0/0/0/0 0/0 "&lt;BADREQ&gt;"
  </code></pre>