nginx - 如何修复:使用 nginx 反向代理时收到错误代码 2 的 RST_STREAM
问题描述
我目前在树莓上使用 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 元数据可能存在问题(尤其是用户代理)。看看这些问题:
推荐阅读
- object - 我的对象场景中的光线有问题
- c++ - 为遍历指针数组的类创建自定义迭代器
- javascript - HTML-Link with javascript:void(0): 它把我带到哪里?
- r - 从 selectInput 到 facet_wrap 的多个变量:R Shiny
- python - 无法使用 Python 连接到普遍数据库
- javascript - 如何使用不同的浏览器来运行电子应用程序而不是电子浏览器
- javascript - 在反应组件中使用 setInterval 重复函数调用的一种替代方法?
- json - D3 - V3:使用从 json 文件加载的数据时的范围错误
- php - 那个简单的 php 类有什么问题?
- python - Splunk 模拟显示源按钮