nginx PRI * HTTP/2.0
问题
通过Nginx 代理 gRPC 服务,其他 client 通过 Nginx 访问后端服务时,后端的 gRPC服务没收到任何请求,发现access_log 是如下信息:
10.0.2.2 - - [24/Sep/2000:08:14:31 +0000] "PRI * HTTP/2.0" 400 173 "-" "-"
检查你的 nginx/conf.d/grpc_proxy.conf 是这样的:
server
{
listen 443 ssl http2;
server_name _;
index index.php index.html index.htm;
root /usr/share/nginx/html/;
ssl on;
ssl_certificate /etc/nginx/cert/server.pem;
ssl_certificate_key /etc/nginx/cert/server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-RSA-AES2...';
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "keep-alive";
proxy_set_header X-Real-IP $remote_addr;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:8080;
}
}
解决否
已解决
方案
我估计你的证书没有被信任,你可以去掉证书试试, 调整后的 nginx/conf.d/grpc_proxy.conf
的配置如下
server
{
listen 443 http2;
root /usr/share/nginx/html/;
access_log /var/log/nginx/access_grpc_proxy.log;
error_log /var/log/nginx/error_grpc_proxy.log;
location / {
# Replace localhost:50051 with the address and port of your gRPC server
# The 'grpc://' prefix is optional; unencrypted gRPC is the default
# grpc_pass grpc://127.0.0.1:8080;
proxy_pass http://127.0.0.1:8080;
}
}
这里我们去掉了nginx的ssl封装。这样就好了。
client 证书
或者你检查下 gRPC client 是否使用了正确的证书,nginx 拦截了流量没到proxy端,估计就是请求认证有问题。
参考
- https://www.nginx.com/blog/nginx-1-13-10-grpc/