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

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

问题描述

我正在将Node服务器与可处理服务器已发送事件流的快速应用一起使用.这是通过启用了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天全站免登陆