我已经让grpc-web运行在react中。这是通过NGINX交流的。此NGINX与运行在docker中的另一个NGINX服务器进行通信,该服务器与我的锈补品http1服务器通信。
对于一个NGINX服务器,下面的配置工作正常:
location /my.EndPoint/ {
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Transfer-Encoding,Custom-Header-1,X-Accept-Content-Transfer-Encoding,X-Accept-Response-Streaming,X-User-Agent,X-Grpc-Web,content-type,snet-current-block-number,snet-free-call-user-id,snet-payment-channel-signature-bin,snet-payment-type,x-grpc-web';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
proxy_pass http://hostname:50051/my.EndPoint/;
}当我使用以下配置将另一个NGINX放在前面时:
location / {
proxy_pass http://192.168.0.xxx:81;
client_max_body_size 5G;
}它停止工作了。我没有得到任何数据。服务器确实收到了请求,但在此之后,请求就不会返回到grpc。
如何通过两个NGINX实例路由grpc?
发布于 2022-09-17 18:53:16
NGINX似乎使用了返回的内容长度标题。
看起来起作用的是删除原来的内容长度标头,并将其添加到最前面的服务器中,如下所示:
location / {
if ($content_type ~ 'application\/grpc(?!-web)(.*)'){
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Transfer-Encoding,Custom-Header-1,X-Accept-Content-Transfer-Encoding,X-Accept-Response-Streaming,X-User-Agent,X-Grpc-Web,content-type,snet-current-block-number,snet-free-call-user-id,snet-payment-channel-signature-bin,snet-payment-type,x-grpc-web';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
}
proxy_pass http://192.168.0.xxx:81;
client_max_body_size 5G;
}https://stackoverflow.com/questions/73757637
复制相似问题