如何修复:使用 nginx 反向代理时收到 RST_STREAM,错误代码为 2

2024-02-18

我目前正在树莓派上使用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/grpc/grpc-go/issues/1888

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何修复:使用 nginx 反向代理时收到 RST_STREAM,错误代码为 2 的相关文章

  • grpc找不到protobuf库

    我检查了 grpc 安装并完成了构建和安装 现在当我尝试 find package gRPC CONFIG REQUIRED I get CMake Error at CMakeLists txt 15 find package Found
  • Kubernetes nginx 入口控制器返回 502,但仅适用于 AJAX/XmlHttpRequest 请求

    我有一个在 nginx 入口控制器后面运行 Kubernetes 的 Web 应用程序 它对于请求浏览工作正常 但来自浏览器的任何 AJAX XMLHTTPRequest 都会从 nginx 收到 502 错误 我捕获了常规请求和 AJAX
  • 如何将多个域路由到多个节点应用程序?

    我习惯了典型的 Lamp Web 托管环境 您只需单击 cpanel 中的几个按钮 您的域就会被分区并映射到 htdocs 中的文件夹 我经常使用 Node js 但做同样的事情似乎并不那么简单 如果我有多个节点应用程序 并且我想将doma
  • NGinx 域名重定向

    假设我有一个名为 xyz co 的网站 我还有其他具有相同前缀的域名 例如 xyz com xyz it xyz co it 现在 nginx 与端口 80 的 nginx conf 中的 server name xyz co 配合得很好
  • 使用 FastCGI 运行 Lua 脚本

    我目前正在尝试找出使用 FastCGI 与 lighttpd 或 Nginx 一起运行 Lua 脚本的方法 我唯一能挖到的是WSAPI http keplerproject github com wsapi 开普勒计划的一部分 但我想知道是
  • Nginx 中 uwsgi_pass 和 proxy_pass 的区别?

    我在 Nginx 后面运行 uWSGI 并一直在使用proxy pass让 Nginx 访问 uWSGI 切换到有什么好处吗uwsgi pass 如果是这样 那是什么 uwsgi pass使用一个uwsgi协议 proxy pass使用普通
  • 如何在位置中使用 Nginx Regexp

    Web 项目将静态内容放入 some content img 文件夹中 url规则为 img some md5 但文件夹中的位置 content img 前两位数字 Example url example com img fe5afe048
  • nginx 匹配位置中的特定单词

    我在匹配 nginx request body 变量中的特定单词时遇到问题 如果正文请求中有特殊单词 我想代理传递 所以我的方法是这样的 location php if request body proxy pass http test p
  • 如何在运行 NGINX Docker 容器的 AWS EC2 上启用 HTTPS?

    我在 AWS 上有一个运行 Amazon Linux 2 的 EC2 实例 在上面 我安装了 Git docker 和 docker compose 完成后 我克隆了我的存储库并运行docker compose up让我的生产环境启动 我访
  • nginx server_name 在流块内可能吗?

    目前设置如下 stream server listen 9987 udp server name subdomain EXAMPLE com this line is resulting in an error proxy pass loc
  • 在 grpc python 中处理异步流请求

    我试图了解如何使用双向流处理 grpc api 使用 Python API 假设我有以下简单的服务器定义 syntax proto3 package simple service TestService rpc Translate stre
  • 将代码从 htaccess 重写为 nginx 配置?

    我在将 htaccess 文件中的重写代码实现到 nginx 配置中时遇到问题 我已经尝试过生成器 http winnginx com htaccess http winginx com htaccess用于生成我的重写 代码 我的ngin
  • 仅使用 GRPC 连接到对话流 StreamingDetectIntent,卡在等待 responseStream.MoveNext

    我正在尝试将 DialogFlow API v2 与 Unity 结合使用 由于 Unity 还没有官方 SDK 所以我使用了 Grpc beta unity SDK 以及使用 Grpc 工具中的 Protobuf 和 protoc 创建的
  • nginx代理认证拦截

    我有几个服务 它们支持 nginx 实例 为了处理身份验证 在 nginx 中 我拦截每个请求并将其发送到身份验证服务 在那里 如果凭据正确 我将设置一个包含用户相关信息的 cookie 现在 请求应该被路由到适当的服务 并设置 cooki
  • Beanstalk 部署忽略 .ebextensions 中的 nginx 配置文件

    我在单实例 Elastic Beanstalk 环境中托管 Java Web 应用程序 并添加了几个 ebextension 文件 这些文件在每次部署时成功为我创建配置文件 然而 我无法找到一种方法让 Beanstalk 在 etc ngi
  • 错误请求 400:nginx/gunicorn

    我已经遵循了这个教程 http blog wercker com 2013 11 25 django 16 part3 html http blog wercker com 2013 11 25 django 16 part3 html我现
  • Logrotate - nginx 日志不在 docker 容器内旋转

    我有一个运行 nginx 的 docker 容器 它正在将日志写入 var log nginxLogrotate 安装在 docker 容器中 并且 nginx 的 logrotate 配置文件已正确设置 尽管如此 logrotate 仍不
  • nginx 上的多个网站和可用网站

    通过 nginx 的基本安装 您的sites available文件夹只有一个文件 default 怎么样sites available文件夹的工作原理以及如何使用它来托管多个 单独的 网站 只是为了添加另一种方法 您可以为您托管的每个虚拟
  • 上游太大 - nginx + codeigniter

    我从 Nginx 收到此错误 但似乎无法弄清楚 我正在使用 codeigniter 并使用数据库进行会话 所以我想知道标题怎么会太大 有没有办法检查标题是什么 或者看看我能做些什么来修复这个错误 如果您需要我提供任何conf文件或其他文件
  • 阻止 ingress-nginx 负载均衡器上的特定路径

    我有许多指向入口控制器 IP 的域 我想阻止所有域 站点的 特定路径 有没有办法做到这一点 我可以用nginx ingress kubernetes io configuration snippet 对于每个站点 但正在寻找同时处理所有站点

随机推荐