title: SSE / EventSource closes after first chunk of data (Rails 4 + Puma + Nginx)
body: <p>I followed the <a href="http://railscasts.com/episodes/401-actioncontroller-live" rel="nofollow noreferrer">401-ActionController-Live</a> Railscast and this <a href="http://tenderlovemaking.com/2012/07/30/is-it-live.html" rel="nofollow noreferrer">Blog Post</a> about <code>Server-Sent-Events</code> to set up something similar in my Rails app. It works perfectly when I open connections to the server when only using <code>puma</code> but with <code>puma + nginx</code>, the connection closes after the first chunk of data is sent.</p>
  
  <p>I also tried following the solutions provided in these questions but they didn't work for me:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/22419434/rails-4-puma-nginx-actioncontrollerlive-streaming-dies-after-first-chunk-s">ActionController::Live Streaming dies after first chunk sent</a></li>
  <li><a href="https://stackoverflow.com/questions/13672743/eventsource-server-sent-events-through-nginx">EventSource / Server-Sent Events through Nginx</a></li>
  </ul>
  
  <p>This is what I'm getting:</p>
  
  <p><img src="https://i.stack.imgur.com/MkIzT.png" alt="Curl response"></p>
  
  <p>This is <a href="https://coderwall.com/p/ttrhow" rel="nofollow noreferrer">How I set up my Server</a> and this is my current <code>nginx</code> configuration:</p>
  
  <pre><code>upstream puma {
    server unix:///home/deploy/apps/outy/shared/tmp/sockets/outy-puma.sock;
    keepalive 16;
  }
  
  server {
    listen 80 default_server deferred;
  
    root /home/deploy/apps/outy/current/public;
    access_log /home/deploy/apps/outy/current/log/nginx.access.log;
    error_log /home/deploy/apps/outy/current/log/nginx.error.log info;
  
    location ^~ /assets/ {
      gzip_static on;
      expires max;
      add_header Cache-Control public;
    }
  
    try_files $uri/index.html $uri @puma;
    location @puma {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
  
      proxy_pass http://puma;
  
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      proxy_buffering off;
      proxy_cache off;
    }
  
    error_page 500 502 503 504 /500.html;
    client_max_body_size 10M;
    keepalive_timeout 10;
  }
  </code></pre>