nginx-http2-grpc
NGINX 官方已发布1.13.10版本,其最主要更新功能点莫过于支持 gRPC 服务代理,即新增的模块ngx_http_grpc_module。
这意味着可以很容易复用 Nginx 现有基础设施,简单几步即可构建出高可用的 gRPC 服务端集群,具体构建概要如下:
搭建 go-grpc 服务,参见 https://grpc.io/docs/quickstart/go.html
$ cd $GOPATH/src/google.golang.org/grpc/examples/helloworld |
搭建 nginx-grpc 代理
nginx 构建支持 http2+grpc
$ wget http://nginx.org/download/nginx-1.13.10.tar.gz -O /tmp/nginx-1.13.10.tar.gz |
配置 nginx 支持 grpc 代理
#vhosts/grpc.conf 配置 demo 文件 |
从上述简单的配置可看出,grpc 模块可以和 upstream 模块结合使用,这意味着可复用 upstream 模块高可用配置,
当然,grpc 模块也提供类似配置,如grpc_next_upstream等。验证 nginx-grpc 代理
启动 nginx 代理服务
$ sudo /usr/local/nginx/sbin/nginx -t && sudo /usr/local/nginx/sbin/nginx |
grpc 服务测验
$ cd $GOPATH/src/google.golang.org/grpc/examples/helloworld |
总体可见,通过 nginx 可以很轻松的构建出高可用的 grpc 服务代理。