gRPC#
Allows passing requests to a gRPC server. The module requires the HTTP/2.
Configuration Example#
server {
listen 9000;
http2 on;
location / {
grpc_pass 127.0.0.1:9000;
}
}
Directives#
grpc_bind#
Makes outgoing connections to a gRPC server originate from the specified local IP address with an optional port. Parameter value can contain variables. The special value off
cancels the effect of the grpc_bind directive inherited from the previous configuration level, which allows the system to auto-assign the local IP address and port.
The transparent
parameter allows outgoing connections to a gRPC server originate from a non-local IP address, for example, from a real IP address of a client:
grpc_bind $remote_addr transparent;
In order for this parameter to work, it is usually necessary to run Angie worker processes with the superuser privileges. On Linux it is not required as if the transparent
parameter is specified, worker processes inherit the CAP_NET_RAW capability from the master process.
Important
It is necessary to configure kernel routing table to intercept network traffic from the gRPC server.
grpc_buffer_size#
Sets the size of the buffer used for reading the first part of the response received from the gRPC server. The response is passed to the client synchronously, as soon as it is received.
grpc_connect_timeout#
Defines a timeout for establishing a connection with a gRPC server. It should be noted that this timeout cannot usually exceed 75 seconds.
grpc_connection_drop#
|
|
Default |
|
http, server, location |
Enables termination of all connections to the proxied server after it has been
removed from the group or marked as permanently unavailable by a reresolve process or the API command
DELETE
.
A connection is terminated when the next read or write event is processed for either the client or the proxied server.
Setting time enables a connection termination timeout;
with on
set, connections are dropped immediately.
grpc_hide_header#
By default, Angie does not pass the header fields "Date", "Server", and "X-Accel-..." from the response of a gRPC server to a client. The grpc_hide_header directive sets additional fields that will not be passed. If, on the contrary, the passing of fields needs to be permitted, the grpc_pass_header directive can be used.
grpc_ignore_headers#
Disables processing of certain response header fields from the gRPC server. The following fields can be ignored: "X-Accel-Redirect" and "X-Accel-Charset".
If not disabled, processing of these header fields has the following effect:
grpc_intercept_errors#
|
|
Default |
|
http, server, location |
Determines whether gRPC responses with codes greater than or equal to 300 should be passed to a client or be intercepted and redirected to Angie for processing with the error_page directive.
grpc_next_upstream#
|
|
Default |
|
http, server, location |
Specifies in which cases a request should be passed to the next server in the upstream pool:
|
an error occurred while establishing a connection with the server, passing a request to it, or reading the response header; |
|
a timeout has occurred while establishing a connection with the server, passing a request to it, or reading the response header; |
|
a server returned an empty or invalid response; |
|
a server returned a response with the code 500; |
|
a server returned a response with the code 502; |
|
a server returned a response with the code 503; |
|
a server returned a response with the code 504; |
|
a server returned a response with the code 403; |
|
a server returned a response with the code 404; |
|
a server returned a response with the code 429; |
|
normally, requests with a non-idempotent method (POST, LOCK, PATCH) are not passed to the next server if a request has been sent to an upstream server; enabling this option explicitly allows retrying such requests; |
|
disables passing a request to the next server. |
Note
One should bear in mind that passing a request to the next server is only possible if nothing has been sent to a client yet. That is, if an error or timeout occurs in the middle of the transferring of a response, fixing this is impossible.
The directive also defines what is considered an unsuccessful attempt of communication with a server.
|
always considered unsuccessful attempts, even if they are not specified in the directive |
|
considered unsuccessful attempts only if they are specified in the directive |
|
never considered unsuccessful attempts |
Passing a request to the next server can be limited by the number of tries and by time.
grpc_next_upstream_timeout#
|
|
Default |
|
http, server, location |
Limits the time during which a request can be passed to the next server.
|
turns off this limitation |
grpc_next_upstream_tries#
|
|
Default |
|
http, server, location |
Limits the number of possible tries for passing a request to the next server.
|
turns off this limitation |
grpc_pass#
Sets gRPC server address. The address can be specified as a domain name or IP address, and a port:
grpc_pass localhost:9000;
or as a UNIX domain socket path:
grpc_pass unix:/tmp/grpc.socket;
Alternatively, the "grpc://" scheme can be used:
grpc_pass grpc://127.0.0.1:9000;
To use gRPC over SSL, the "grpcs://" scheme should be used:
grpc_pass grpcs://127.0.0.1:443;
If a domain name resolves to several addresses, all of them will be used in a round-robin fashion. In addition, an address can be specified as a server group. If a group is used, you cannot specify the port with it; instead, specify the port for each server within the group individually.
Parameter value can contain variables. In this case, if an address is specified as a domain name, the name is searched among the described server groups, and, if not found, is determined using a resolver.
grpc_pass_header#
Permits passing otherwise disabled header fields from a gRPC server to a client.
grpc_read_timeout#
Defines a timeout for reading a response from the gRPC server. The timeout is set only between two successive read operations, not for the transmission of the whole response. If the gRPC server does not transmit anything within this time, the connection is closed.
grpc_send_timeout#
Sets a timeout for transmitting a request to the gRPC server. The timeout is set only between two successive write operations, not for the transmission of the whole request. If the gRPC server does not receive anything within this time, the connection is closed.
grpc_set_header#
|
|
Default |
|
http, server, location |
Allows redefining or appending fields to the request header passed to the gRPC server. The value can contain text, variables, and their combinations. These directives are inherited from the previous configuration level if and only if there are no grpc_set_header directives defined on the current level.
If the value of a header field is an empty string then this field will not be passed to a gRPC server:
grpc_set_header Accept-Encoding "";
grpc_socket_keepalive#
|
|
Default |
|
http, server, location |
Configures the "TCP keepalive" behavior for outgoing connections to a gRPC server.
|
By default, the operating system's settings are in effect for the socket. |
|
The SO_KEEPALIVE socket option is turned on for the socket. |
grpc_ssl_certificate#
Specifies a file with the certificate in the PEM format used for authentication to a gRPC SSL server. Variables can be used in the file name.
grpc_ssl_certificate_key#
Specifies a file with the secret key in the PEM format used for authentication to a gRPC SSL server.
The value "engine:name:id" can be specified instead of the file, which loads a secret key with a specified id from the OpenSSL engine name. Variables can be used in the file name.
grpc_ssl_ciphers#
Specifies the enabled ciphers for requests to a gRPC SSL server. The ciphers are specified in the format understood by the OpenSSL library.
The full list can be viewed using the "openssl ciphers" command.
grpc_ssl_conf_command#
Sets arbitrary OpenSSL configuration commands when establishing a connection with the gRPC SSL server.
Important
The directive is supported when using OpenSSL 1.0.2 or higher.
Several grpc_ssl_conf_command directives can be specified on the same level. These directives are inherited from the previous configuration level if and only if there are no grpc_ssl_conf_command directives defined on the current level.
Caution
Note that configuring OpenSSL directly might result in unexpected behavior.
grpc_ssl_crl#
Specifies a file with revoked certificates (CRL) in the PEM format used to verify the certificate of the gRPC SSL server.
grpc_ssl_name#
|
|
Default |
|
http, server, location |
Allows overriding the server name used to verify the certificate of the gRPC SSL server and to be passed through SNI when establishing a connection with the gRPC SSL server.
By default, the host part of the grpc_pass URL is used.
grpc_ssl_password_file#
Specifies a file with passphrases for secret keys where each passphrase is specified on a separate line. Passphrases are tried in turn when loading the key.
grpc_ssl_protocols#
|
|
Default |
|
http, server, location |
Changed in version 1.2.0: TLSv1.3
parameter added to default set.
Enables the specified protocols for requests to a gRPC HTTPS server.
grpc_ssl_server_name#
|
|
Default |
|
http, server, location |
Enables or disables passing the server name set by the grpc_ssl_name directive via the Server Name Indication TLS extension (SNI, RFC 6066) while establishing a connection with the gRPC SSL server.
grpc_ssl_session_reuse#
|
|
Default |
|
http, server, location |
Determines whether SSL sessions can be reused when working with the gRPC server. If the errors "SSL3_GET_FINISHED:digest check failed" appear in the logs, try disabling session reuse.
grpc_ssl_trusted_certificate#
Specifies a file with trusted CA certificates in the PEM format used to verify the certificate of the gRPC SSL server.
grpc_ssl_verify#
Enables or disables verification of the gRPC SSL server certificate.
grpc_ssl_verify_depth#
|
|
Default |
|
http, server, location |
Sets the verification depth in the gRPC SSL server certificates chain.