Rails 4, Puma, Nginx - ActionController::Live Streaming dies after first chunk sent

自作多情 提交于 2019-12-03 12:14:15

Solved

It turns out all that I needed was this line in my location directive to get streaming working through nginx:

proxy_http_version 1.1;

I discovered this fix when investigating the keepalive directive in nginx's upstream module:

http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive

This piece of text in particular clued me in:

For HTTP, the proxy_http_version directive should be set to “1.1” and the “Connection” header field should be cleared:

upstream http_backend {
    server 127.0.0.1:8080;

    keepalive 16;
}

server {
    ...

    location /http/ {
        proxy_pass http://http_backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        ...
    }
}

It seems that nginx defaults to, proxy_http_version 1.0;

And according to Wikipedia, http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

HTTP/1.1 introduced chunked transfer encoding to allow content on persistent connections to be streamed rather than buffered.

So there was my problem.

TIL

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!