A gRPC service behind nginx returns 502 and the log says `upstream sent no valid HTTP/1.0 header while reading response header from upstream`.
AdvancedTroubleshootingLoad balancers and reverse proxies
Answer
Likely causes → nginx is configured with proxy_pass, which speaks HTTP/1.x to upstreams, but the gRPC server only speaks HTTP/2 (h2c). The server answers with HTTP/2 frames, which nginx can't parse as an HTTP/1 response.
Diagnose →
nginx -T | grep -B5 -A5 'proxy_pass.*50051'
grpcurl -plaintext 127.0.0.1:50051 list # confirm the backend works directly
Fix →
server {
listen 443 ssl;
http2 on;
location / {
grpc_pass grpc://127.0.0.1:50051; # grpcs:// if the backend uses TLS
grpc_read_timeout 300s;
}
}
Prevent → Use protocol-aware proxies for gRPC (nginx grpc_pass, Envoy, ALB target groups with protocol version GRPC).
More on Load balancers and reverse proxies
nginx returns `502 Bad Gateway` and the error log says `connect() failed (111: Connection refused) while connecting to upstream`.Beginnernginx returns `504 Gateway Time-out` with `upstream timed out (110: Connection timed out) while reading response header from upstream`.BeginnerAn ALB target group shows all targets `unhealthy` with `Health checks failed with these codes: [404]`.BeginnerAn ALB returns sporadic `502`s, and access logs show `elb_status_code=502` with `target_status_code=-`. Load is low.Intermediatenginx logs `upstream prematurely closed connection while reading response header from upstream`.Intermediatenginx error log shows `no live upstreams while connecting to upstream` and every request gets 502.Intermediate