文章

nginx没有流式传输的原因

一种可能原因是经过 Nginx 反向代理,开启了 buffer,则 Nginx 会尝试从后端缓冲一定大小的数据再发送给浏览器。请尝试在反代参数后添加 proxy_buffering off;,然后重载 Nginx。其他 web server 配置同理。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
server {
    listen 443 ssl;
    server_name chat.masterke.cn;

    ssl_certificate /etc/letsencrypt/live/masterke.cn/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/masterke.cn/privkey.pem;
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout 5m;
    location / {
        proxy_pass http://127.0.0.1:3002;
        proxy_redirect off;
        proxy_http_version 1.1;
        sub_filter_once off;
        proxy_set_header Host $http_host;
        proxy_set_header Referer $http_referer;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header User-Agent $http_user_agent;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Accept-Encoding "";
        proxy_set_header Accept-Language "zh-CN";
        proxy_buffering off;
        proxy_cache off;
    }
}
本文由作者按照 CC BY 4.0 进行授权