我使用的是一元 RPC 方法。我有一个在 Nginx Web 服务器下配置的服务器。以下是 Nginx 配置:
server {
listen 80 http2;
server_name test.grpc.tester.local;
access_log /var/log/nginx/test.grpc.tester.local.access.log;
error_log /var/log/nginx/test.grpc.tester.local.error.log;
location / {
grpc_pass grpc://localhost:8001;
}
}
我有一个客户端也可以在同一主机上使用。我以几种方式调用这个一元方法,并且我有以下观察结果:
如果我使用 Nginx 代理(test.grpc.tester.local:80)调用服务器 RPC 方法,并且如果花费时间超过 1 分钟,则会出现错误:
Nginx的错误日志中:
upstream timed out (110: Connection timed out) while reading response header from upstream
在客户端日志中:
Error: 1 CANCELLED: Received http2 header with status: 504
。
如果我不使用Nginx并直接使用localhost:8001访问,它永远不会给出错误(即使服务器需要超过1分钟)并给出成功状态。
我在这里的疑问是如何增加请求时间,这样我就不会收到超时错误。我已经尝试过以下配置,但没有成功:
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
任何人都可以指导我如何解决这个问题吗?
谢谢你。
我遇到了同样的问题,似乎可以通过以下配置修复;
location /grpweburl
{
proxy_pass http://localhost:5000/grpweburl;
proxy_request_buffering off;
proxy_buffering off;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
}
请注意 - 我正在使用 grpc-web。不只是grpc。但我怀疑添加缓冲设置会解决您的问题,就像对我一样。
我不确定为什么这个组合会起作用,但它对我来说确实有效。缓冲部分是为了确保数据更新立即发送到客户端。
结合超时设置,如果 grpc-service 没有给出结果,我现在只会每 10 分钟从 nginx 获取一次 http-504。正如预期的那样。
为了不干扰正常操作,我只为 grpc-web url 设置这些配置设置。
我遇到了同样的问题,并通过 Ngnix conf 中的以下更改修复了它。
server {
listen 9095;
http2 on;
location / {
grpc_pass grpc://server1;
grpc_connect_timeout 600s;
grpc_read_timeout 600s;
grpc_send_timeout 600s;
}
}