gpt4 book ai didi

grpc-web - 我们可以在不依赖 docker 的情况下使用 nginx 代理进行 gRPC-web 集成吗?

转载 作者:行者123 更新时间:2023-12-03 20:16:02 24 4
gpt4 key购买 nike

需要在没有 docker 的情况下使用 NGINX

我尝试使用具有 docker 依赖关系的 envoy 代理使用 gRPC-web 集成,所以我转移到 NGINX,如何在没有 docker 依赖关系的情况下使用 NGINX?

最佳答案

由于没有直接支持 grpc-web来自 nginx ,我们可以在 nginx 的配置文件中进行以下 hack 以同时使用 grpc-webgrpc调用。

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;
}
}

上述配置基于内容类型机制工作,每当 grpc-web调用 nginx,内容类型为 application/grpc-web并且此内容类型未由 nginx 处理 grpc_pass .

因此,只有那些内容类型为 application/grpc+(proto|json|customType) 的请求与 grpc_pass 合作而其余的请求将与 proxy_pass 一起使用.

关于grpc-web - 我们可以在不依赖 docker 的情况下使用 nginx 代理进行 gRPC-web 集成吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54440325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com