Chrome net::ERR_HTTP2_PROTOCOL_ERROR 200 重新连接后 [英] Chrome net::ERR_HTTP2_PROTOCOL_ERROR 200 after a reconnect

查看:69
本文介绍了Chrome net::ERR_HTTP2_PROTOCOL_ERROR 200 重新连接后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Node 服务器与处理服务器发送事件流的 express 应用程序一起使用.这是通过启用 http2 的 NginX 代理的.SSE 事件通过 React 应用程序中的 EventSource 使用.我每 10 秒发送一次心跳消息以保持连接有效.

I'm using Node server with an express app which handles a Server Sent Events stream. This is proxied via NginX with http2 enabled. The SSE events are consumed via EventSource in a React app. I'm sending a heartbeat message every 10 seconds to keep the connection alive.

这一切都很好,直到出现某种形式的网络中断,例如让我的笔记本电脑进入睡眠状态然后重新唤醒它.

This all works great until there is some form of network interruption such as putting my laptop to sleep then re-awaking it.

然后从那时起,流上的流将每 40 秒左右出错一次,并显示 net::ERR_HTTP2_PROTOCOL_ERROR 200 错误,然后重新连接而不是仅使用稳定流重新连接一次.

Then from that point on the stream will error every 40 or so seconds with the net::ERR_HTTP2_PROTOCOL_ERROR 200 error and then reconnect instead of just reconnecting once with a steady stream.

Firefox 工作正常.它不会出错并且只重新连接一次.

Firefox works correctly. It doesn't error and reconnects only once.

如果我将 Node 配置为直接为 http2 提供服务,而不是通过 NGinx 作为测试(通过 spdy 库),那么一切都按预期工作,所以我不认为这是一个 Node 问题,我必须在我的 Nginx 配置中遗漏一些东西和铬合金.

If I configure Node to serve http2 directly instead of via NGinx as a test (via spdy library) then all works as expected so I don't think this is a Node issue and I must be missing something with my Nginx configuration and Chrome.

Nginx 配置如下(位置/stream 为 SSE 代理)

Nginx config as follows (location /stream is the SSE proxy)

server {
    listen 28443 ssl http2;
    listen [::]:28443 ssl http2;

    server_name example.com;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    http2_max_field_size 16k;
    http2_max_header_size 128k;

    root /var/www/example.com;
    index index.html index.htm;

    location / {
        client_max_body_size 100M;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://localhost:28080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'Upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /stream {
        proxy_http_version 1.1;
        # proxy_request_buffering off;
        # proxy_buffering off;
        # proxy_cache off;
        # chunked_transfer_encoding off;
        proxy_set_header    Connection          '';
        proxy_set_header  Host            $host;
        proxy_set_header  X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:28080/stream;
    }
}

我尝试了关闭 proxy_buffers 和 keepalive 设置等的各种组合.这似乎只影响错误之间的时间,即 5 分钟而不是 40 秒.

I've tried various combinations with proxy_buffers off and keepalive settings ect.. which seems to only affect the time between errors i.e. 5 minutes instead of 40 seconds.

推荐答案

不确定你是否明白这一点.通过增加大小,我最近遇到了同样的问题:

Not sure if you figure this out. I got the same issue recently, by increasing the size:

http2_max_field_size 64k;
http2_max_header_size 512k;

chrome 的 net::ERR_HTTP2_PROTOCOL_ERROR 已经消失了.

The chrome's net::ERR_HTTP2_PROTOCOL_ERROR has gone.

另外,不确定它是否适用于您.如果我使用 firefox,我实际上可以正确访问我的网站.

Also, not sure if it applied to you. If I use firefox, I can actually visit my site correctly.

这篇关于Chrome net::ERR_HTTP2_PROTOCOL_ERROR 200 重新连接后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆