首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我们是否可以使用nginx代理进行gRPC-web集成,而不依赖docker?

我们是否可以使用nginx代理进行gRPC-web集成,而不依赖docker?
EN

Stack Overflow用户
提问于 2019-01-30 20:09:46
回答 2查看 3.2K关注 0票数 4

需要使用不带docker的NGINX

我尝试过使用具有docker依赖关系的特使代理来使用gRPC-web集成,所以我转移到了NGINX,如何使用没有docker依赖关系的NGINX?

EN

回答 2

Stack Overflow用户

发布于 2019-10-11 13:24:38

由于nginx不直接支持grpc-web,我们可以在nginx的配置文件中使用下面的hack来处理grpc-webgrpc调用。

代码语言:javascript
复制
server {
    listen 1449 ssl http2;
    server_name `domain-name`;
    ssl_certificate `pem-file`; # managed by Certbot
    ssl_certificate_key `key-file`; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location / {

    #
    ## Any request with the content-type application/grpc+(json|proto|customType) will not enter the
    ## if condition block and make a grpc_pass while rest of the requests enters into the if block
    ## and makes a proxy_prass request. Explicitly grpc-web will also enter the if block.
    #

    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://reroute_url;
    }
    grpc_pass grpc://reroute_url;
    }
}

上面的配置是基于content-type机制工作的,每当grpc-web调用nginx时,content-type将是application/grpc-web,并且这个content-type不会被nginx用grpc_pass处理。

因此,只有那些内容类型为application/grpc+(proto|json|customType)的请求才适用于grpc_pass,而其余的请求将适用于proxy_pass

票数 6
EN

Stack Overflow用户

发布于 2019-03-26 11:11:49

您可以查看dockerfile的功能,并在docker图像之外自行完成此操作:https://github.com/grpc/grpc-web/blob/master/net/grpc/gateway/docker/nginx/Dockerfile

主要是运行make standalone-proxy,并以./gConnector_static/nginx.sh的身份运行它。您将需要一个nginx.conf配置文件来指定Nginx应该在何处接收和转发gRPC请求

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54440325

复制
相关文章

相似问题

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