title: Server Sent Events / EventSource with Sinatra on Elastic Beanstalk
body: <p>I am using Amazon Elastic Beanstalk (Nginx 1.4.2 + Passenger 4.0.20 + Ruby 1.9.3) to deploy a sinatra app that uses Server Sent Events. Everything works perfectly on local machine using thin. On AWS Elastic Beanstalk though, the connection gets dropped after milliseconds. </p>
  
  <p>server code look like this:</p>
  
  <pre><code>get '/stream', provides: 'text/event-stream' do
    response.headers['X-Accel-Buffering'] = 'no'
    stream :keep_open do |out|
      settings.connections &lt;&lt; out
      out.callback { settings.connections.delete(out) }
    end
  end
  </code></pre>
  
  <p>On the server log I see a connection timeout:</p>
  
  <p><code>2013/11/20 19:45:46 [info] 9716#0: *35 client closed connection while waiting for request, client: xxx.xxx.xxx.xxx, server: 0.0.0.0:80</code></p>
  
  <p>Tried the nginx configuration suggested here (<a href="https://stackoverflow.com/questions/13672743/eventsource-server-sent-events-through-nginx">EventSource / Server-Sent Events through Nginx</a>) under the server block and although the header response changes, it is not yet working.</p>
  
  <p>(I had to set X-Accell-Buffering on Nginx file as well, because it would not take the setting set in server code with sinatra)</p>
  
  <p>Response header looks something like this:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Content-Type: text/event-stream;charset=utf-8
  Date: Wed, 20 Nov 2013 20:03:06 GMT
  Server: nginx/1.4.2 + Phusion Passenger 4.0.20
  Status: 200 OK
  X-Accel-Buffering: no
  X-Content-Type-Options: nosniff
  X-Powered-By: Phusion Passenger 4.0.20
  transfer-encoding: chunked
  Connection: keep-alive
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks in advance.</p>