Nginx gRPC Proxy Configuration
What an RPC looks like
A remote procedure call (RPC) asks a service to perform a named operation. A unary call sends one request and receives one response. In this chapter, a fictional Catalog service has an Echo operation accepting a protobuf StringValue and returning the same text with a prefix. A native gRPC call carries serialized messages and metadata over HTTP/2. Protocol Buffers are common, but a gRPC message is not simply an ordinary JSON HTTP body. The client must use the matching service and message contract.
syntax = "proto3";package lab;import "google/protobuf/wrappers.proto";service Catalog { rpc Echo(google.protobuf.StringValue) returns (google.protobuf.StringValue); rpc List(google.protobuf.StringValue) returns (stream google.protobuf.StringValue);}The unary method path is /lab.Catalog/Echo. The fixture uses standard generated wrapper messages and Python generic handlers, so no additional generated files are needed.
Route native gRPC
Use grpc_pass from the HTTP gRPC module (introduced in 1.13.10; HTTP/2 module required). The location below is deliberately restricted to the service prefix, and the backend is a fixed loopback endpoint. grpc_set_header sets forwarded request metadata; a fixed value demonstrates an edge-controlled marker rather than trusting a client claim. The cleartext backend hop is acceptable only inside the isolated lab.
location /lab.Catalog/ { grpc_pass grpc://127.0.0.1:50051; grpc_set_header X-Lab-Edge bytemind; grpc_next_upstream off;}The backend receives the original RPC path. The lab tests that it sees the fixed metadata even if a caller supplied a different value. Do not copy proxy_pass URI-suffix rules into grpc_pass. Do not mix native gRPC with gRPC-Web without a compatible translation layer.
Read both HTTP and RPC outcomes
A trailer is metadata sent at the end of a response. Native gRPC normally conveys its application result in grpc-status, which may also appear in a trailers-only response. Status 0 means OK; nonzero values signal a failed RPC. HTTP 200 on its own does not indicate RPC success. Nginx forwards upstream gRPC trailers without interpreting them. Ordinary HTTP upstream status counters are therefore insufficient for RPC success metrics.
:status: 200content-type: application/grpc...grpc-status: 3grpc-message: invalid%20inputStatus 3 is INVALID_ARGUMENT. An HTTP success counter would miss this application failure. Transport failures may produce a non-200 response or no valid gRPC status; use the client library result to classify them.
Secure the separate upstream hop
TLS between the caller and Nginx does not encrypt the hop to the service. In production, use a verified upstream TLS endpoint where the trust boundary requires it. grpc_ssl_verify is off by default, so enable it explicitly and configure a trust anchor and the expected service DNS identity. This is a separate, illustrative alternative to the plaintext loopback fixture; certificate files and a TLS gRPC backend must exist first.
location /lab.Catalog/ { grpc_pass grpcs://127.0.0.1:50052; grpc_ssl_server_name on; grpc_ssl_name catalog.test; grpc_ssl_trusted_certificate certs/backend-ca.crt; grpc_ssl_verify on; grpc_next_upstream off;}The backend must present a certificate trusted by backend-ca.crt and matching catalog.test. SNI helps select the certificate but is not itself identity verification. Mutual authentication additionally uses grpc_ssl_certificate and grpc_ssl_certificate_key when required.
Practice and next step
Practice reading RPC status before diagnosing an application failure. Next: streaming and limits. Use the chapter 22 manual exercise and optional lab. All configuration samples are static; no ByteMind execution is implied.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Nginx gRPC Proxy Configuration
Route a unary RPC through Nginx, interpret gRPC status, and configure verified TLS for the upstream hop.
Which fixture path invokes the unary Echo RPC?
Which directive routes native gRPC to a fixed local service?
HTTP status 200 and grpc-status 3 are observed. How should the call be classified?
Which change verifies a TLS backend identity?
Why set a fixed X-Lab-Edge header?