nginx 接入gRPC
程序员文章站
2022-05-27 22:52:44
...
nginx 1.13.10新增了对gRPC的支持,本文介绍通过nginx接入grpc服务。
一. nginx版本
$ nginx -V nginx version: nginx/1.15.6 built by clang 10.0.0 (clang-1000.11.45.5) built with OpenSSL 1.0.2p 14 Aug 2018 TLS SNI support enabled --with-http_ssl_module --with-http_v2_module
若源码安装,需指定http2编译选项:--with-http_v2_module
二. grpc负载均衡配置
#grpc服务列表 upstream grpcservs { server 127.0.0.1:80; } server { listen 8080 http2; #配置http2 server_name localhost; #location配置 location /helloworld.Greeter { grpc_pass grpc://grpcservs; } }
三. 测试
设置greeter_client 连接端口为8080。
$ ./greeter_client
Greeter received: Hello world
nginx访问日志:
127.0.0.1 - - [05/Feb/2019:11:01:49 +0800] "POST /helloworld.Greeter/SayHello HTTP/2.0" 200 18 "-" "grpc-c++/1.18.0 grpc-c/7.0.0 (osx; chttp2; goose)" "-"
可见nginx配置生效,通过http2协议通信。
四. 抓包分析
上一篇: linux addr2line