2014-09-04 29 views
7

Rails uygulamasında benzer bir şey ayarlamak için 401-ActionController-Live Railscast ve Blog Post yaklaşık Server-Sent-Events'u izledim. Yalnızca puma ancak puma + nginx ile sunucuya bağlantıları açtığımda, verilerin ilk yığını gönderildikten sonra bağlantı kapanırsa mükemmel çalışır.SSE/EventSource, verilerin ilk kümesinden sonra kapanır (Rails 4 + Puma + Nginx)

Ben de bu sorulara verilen çözümleri aşağıdaki çalıştı ama onlar benim için işe yaramadı:

Bu alıyorum budur:

Curl response

Bu How I set up my Server ve bu benim şimdiki nginx yapılandırması:

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; 
} 
+0

çözerseniz Are senin sorunun? – arturtr

+0

@arturtr no, hala bu sorunu çözemedim – Sheharyar

cevap

1

çalıştığım yapılandırmayı paylaşacak. onunla

nginx

upstream app_server { 
    server unix:/var/tmp/sockets/puma.sock 
    fail_timeout=0; 
} 

server { 
    listen 80 default_server; 
    listen 443 ssl; 
    client_max_body_size 8m; 
    server_tokens off; 

    server_name localhost; 

    keepalive_timeout 5; 

    location/{ 
     try_files @uri @app; 
    } 

    location @app { 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; 
     proxy_set_header Host $http_host; 
     proxy_redirect off; 

     proxy_http_version 1.1; 
     chunked_transfer_encoding off; 

     proxy_buffering off; 

     proxy_pass http://app_server; 
    } 
} 

kontrolör

class StreamController < ActionController::Base 
    include ActionController::Live 

    def hello 
    response.headers["Content-Type"] = "text/event-stream" #; charset=utf-8" 

    10.times { 
     response.stream.write("data: Hello World!!\n\n") 
     sleep 1 
    } 
    rescue IOError 
    puts "Stream IO Error" 
    logger.info "Stream IO Error" 
    ensure 
    puts "Stream closed" 
    logger.info "Stream closed" 
    response.stream.close 
    end 
end 

bukle

$ curl -i -N http://localhost/stream/hello 
HTTP/1.1 200 OK 
Server: nginx 
Date: Wed, 29 Jul 2015 09:15:43 GMT 
Content-Type: text/event-stream 
Transfer-Encoding: chunked 
Connection: keep-alive 
X-Frame-Options: SAMEORIGIN 
X-XSS-Protection: 1; mode=block 
X-Content-Type-Options: nosniff 
Cache-Control: no-cache 
X-Request-Id: 41e80567-d792-4a48-9ec3-c661aa056081 
X-Runtime: 0.062282 
Vary: Origin 

data: Hello World!! 

data: Hello World!! 

data: Hello World!! 

data: Hello World!! 

data: Hello World!! 

data: Hello World!! 

data: Hello World!! 

data: Hello World!! 

data: Hello World!! 

data: Hello World!! 
+0

Bu yanıtta, nginx yapılandırmasında anahtar satırı "proxy_http_version 1.1;", geri kalan isteğe bağlıydı, en azından benim kurulumumda –