首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grpc-web背后的双nginx

grpc-web背后的双nginx
EN

Stack Overflow用户
提问于 2022-09-17 18:46:46
回答 1查看 12关注 0票数 0

我已经让grpc-web运行在react中。这是通过NGINX交流的。此NGINX与运行在docker中的另一个NGINX服务器进行通信,该服务器与我的锈补品http1服务器通信。

对于一个NGINX服务器,下面的配置工作正常:

代码语言:javascript
复制
        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放在前面时:

代码语言:javascript
复制
  location / {
    proxy_pass http://192.168.0.xxx:81;
    client_max_body_size 5G;
  }

它停止工作了。我没有得到任何数据。服务器确实收到了请求,但在此之后,请求就不会返回到grpc。

如何通过两个NGINX实例路由grpc?

EN

回答 1

Stack Overflow用户

发布于 2022-09-17 18:53:16

NGINX似乎使用了返回的内容长度标题。

看起来起作用的是删除原来的内容长度标头,并将其添加到最前面的服务器中,如下所示:

代码语言:javascript
复制
  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;
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73757637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档