本文介绍了如何修复:使用nginx反向代理时收到RST_STREAM,错误代码为2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在覆盆子上使用Dialogflow API。使用GRPC调用StreamingDetectIntent方法时,一切正常。我必须在我的产品上使用多个API,因此,我试图在它们之前放置一个反向代理。就这样,我只能呼叫一个地址我正在使用nginx将我的GRPC请求反向代理到Google API。我在调用简单方法时没有问题,但在调用StreamingDetectIntent这样的流方法时,我在请求期间遇到了错误。

Dialogflow从我的客户端获取音频流量没有问题,但我在获取请求的最后一部分,即下行流量时遇到了问题。

以下是我的客户给我的错误:

grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.INTERNAL
        details = "Received RST_STREAM with error code 2"
        debug_error_string = "{"created":"@1567173815.816362297","description":"Error received from peer ipv4:163.172.143.250:443","file":"src/core/lib/surface/call.cc","file_line":1041,"grpc_message":"Received RST_STREAM with error code 2","grpc_status":13}"
>

这里是我在nginx日志中看到的错误:

upstream sent frame for closed stream 1 while reading upstream, client: ..., server: exemple.com, request: "POST /google.cloud.dialogflow.v2beta1.Sessions/StreamingDetectIntent HTTP/2.0", upstream: "grpcs://...:443", host: "example.com:443"
我已尝试将GRPC_BUFFER_SIZE参数增加到较大值,但不起作用。

这是我当前的Nginx配置:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log debug;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {

    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    client_max_body_size 4000M;
    grpc_read_timeout 1d;
    grpc_send_timeout 1d;
    # this seems to fix it; but see comment in README.md
    grpc_buffer_size 100M;

    include /etc/nginx/conf.d/*.conf;

    server {

        # SSL configuration
        listen 443 ssl http2;

        access_log /var/log/nginx/access_grpc.log main;

        location / {
            grpc_pass grpcs://dialogflow.googleapis.com:443;
        }

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key/etc/letsencrypt/live/exemple.com/privkey.pem;
    }

    server {

        if ($host = example.com) {
            return 301 https://$host$request_uri;
        }

        listen 80 ;
        listen [::]:80 ;

        return 404; # managed by Certbot

    }

}

推荐答案

GRPC元数据可能有问题(尤其是用户代理)。请看以下问题:

https://github.com/grpc/grpc-go/issues/1888

https://github.com/improbable-eng/grpc-web/issues/145

这篇关于如何修复:使用nginx反向代理时收到RST_STREAM,错误代码为2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 06:12