gRPC#
Allows passing requests to a gRPC server.
Note
This module requires the HTTP/2 module.
When building from the source code, the module is built by
default; it can be disabled with the build option
--without-http_grpc_module.
In packages and images from our repositories, the
module is included in the build. 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 By default, this value is evaluated once when the request is initialized, before
a gRPC server is selected. In Angie PRO, evaluation happens after each gRPC
server selection (including retries), so the bind address can depend on the
selected server; for example, via the The 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 Note It is necessary to configure kernel routing table to intercept network traffic from the gRPC server. 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. Defines a timeout for establishing a connection with a gRPC server. It should be noted that this timeout cannot usually exceed 75 seconds. Note This timeout does not govern idle connections: how long an already-open one
is kept for reuse is set by keepalive_timeout in an upstream block
whose connections are cached with keepalive. Default http, server, location Enables termination of all active 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
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 By default, Angie does not pass the header fields Disables processing of certain response header fields from the gRPC server. The following fields can be ignored: If not disabled, processing of these header fields has the following effect: Determines whether gRPC server 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. Default http, server, location Specifies in which cases a request should be passed to the next server in the upstream group: 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
( 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. Default http, server, location Limits the time during which a request can be passed to the next server. turns off this limitation Default http, server, location Limits the number of possible tries for passing a request to the next server. turns off this limitation Sets the gRPC server address. The address can be specified as a domain name or IP address, and a port: or as a UNIX domain socket path: Alternatively, the To use gRPC over SSL, the 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. 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. The request URI is passed in the Note If Permits passing otherwise disabled header fields from a gRPC server to a client. 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. 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. Default http, server, location Allows redefining or appending fields to the request header passed to the gRPC server. The value can contain variables. 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 the gRPC server: 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. Specifies the certificate in the PEM format used for authentication to a gRPC SSL server. The value is interpreted as in ssl_certificate: a file path, or the PEM
text of the certificate after the Default http, server, location Defines a cache that stores SSL certificates and secret keys specified using variables. The directive supports the following parameters: Keys protected by a passphrase (see grpc_ssl_password_file) are not cached. Example: Default — http, server, location Specifies the secret key in the PEM format used for authentication to a gRPC SSL server. The value, including the Specifies the enabled ciphers for requests to a gRPC SSL server. The ciphers are specified in the format understood by the OpenSSL library. The list of ciphers depends on the version of OpenSSL installed.
The full list can be viewed using the Warning With OpenSSL, the With LibreSSL, TLS 1.3 ciphers can be configured using
With BoringSSL, TLS 1.3 ciphers cannot be configured at all. Sets arbitrary OpenSSL configuration commands when establishing a connection with the gRPC SSL server. Note The directive is supported when using OpenSSL 1.0.2 or higher.
The 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. Warning Note that configuring OpenSSL directly might result in unexpected behavior. Specifies a file with revoked certificates (CRL) in the PEM format used to verify the certificate of the gRPC SSL server. 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. The server name can also be specified with variables. By default, the host name from grpc_pass is used. 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. Default http, server, location Enables the specified protocols for requests to a gRPC SSL server. 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. Default http, server, location Determines whether SSL sessions can be reused when working with the gRPC server. If the Specifies a file with trusted CA certificates in the PEM format used to verify the certificate of the gRPC SSL server. Enables or disables verification of the gRPC SSL server certificate. Sets the verification depth in the gRPC SSL server certificates chain.Configuration Example#
server {
listen 9000;
http2 on;
location / {
grpc_pass 127.0.0.1:9000;
}
}
Directives#
grpc_bind#
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.$upstream_current_addr variable.
If the evaluated value is empty, no binding is made.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;
transparent parameter is specified, worker processes inherit the CAP_NET_RAW capability from the master process.grpc_buffer_size#
grpc_connect_timeout#
grpc_connection_drop#
grpc_connection_drop time | on | off;grpc_connection_drop off;DELETE.
Idle connections in the cache are not affected.on set, connections are dropped immediately.grpc_hide_header#
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#
X-Accel-Redirect and X-Accel-Charset.X-Accel-Redirect performs an internal redirect to the specified URI or
named location;X-Accel-Charset sets the desired charset of a response.grpc_intercept_errors#
grpc_next_upstream#
grpc_next_upstream error | timeout | invalid_header | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | http_429 | non_idempotent | off ...;grpc_next_upstream error timeout;errortimeoutinvalid_headerhttp_500http_502http_503http_504http_403http_404http_429non_idempotentPOST, 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;offerror, timeout, invalid_headerhttp_500, http_502, http_503, http_504, http_429http_403, http_404grpc_next_upstream_timeout#
grpc_next_upstream_timeout time;grpc_next_upstream_timeout 0;0grpc_next_upstream_tries#
grpc_next_upstream_tries number;grpc_next_upstream_tries 0;0grpc_pass#
grpc_pass localhost:9000;
grpc_pass unix:/tmp/grpc.socket;
grpc:// scheme can be used:grpc_pass grpc://127.0.0.1:9000;
grpcs:// scheme should be used:grpc_pass grpcs://127.0.0.1:443;
:path pseudo-header field by the same
rule as with proxy_pass without a URI: exactly as the
client sent it, unless Angie has changed the URI or the arguments of the request.grpc_pass is specified in a location with a trailing slash in the prefix
(for example, location /name/),
and the auto_redirect directive is set to default,
requests without a trailing slash will be redirected (/name -> /name/).grpc_pass_header#
grpc_read_timeout#
grpc_send_timeout#
grpc_set_header#
grpc_set_header field value;grpc_set_header Content-Length $content_length;grpc_set_header Accept-Encoding "";
grpc_socket_keepalive#
offongrpc_ssl_certificate#
data: prefix. The value can contain
variables; they are evaluated each time Angie establishes a connection to the
gRPC SSL server, so all variables of the request are available, including those
assigned by set. If the evaluated certificate value is empty, no client
certificate is sent. To avoid loading certificates for every connection, enable
grpc_ssl_certificate_cache.grpc_ssl_certificate_cache#
grpc_ssl_certificate_cache off;grpc_ssl_certificate_cache max=N [inactive=time] [valid=time];grpc_ssl_certificate_cache off;max — sets the maximum number of elements in the cache. When the cache
overflows, the least recently used (LRU) elements are removed.inactive — defines the time after which an element is removed if it
has not been accessed during this time, even if still within its
valid period; each access resets this timer. The default is 10
seconds.valid — defines the time during which a cached element is reused
without checks. The default is 60 seconds. After this period, an element
loaded from a file is reloaded only if the file has changed, and a key
loaded with the engine: or store: prefix is loaded again; an
element specified with the data: prefix stays valid.off — disables the cache.grpc_ssl_certificate /etc/angie/ssl/$host.crt;
grpc_ssl_certificate_key /etc/angie/ssl/$host.key;
grpc_ssl_certificate_cache max=1000 inactive=20s valid=1m;
grpc_ssl_certificate_key#
grpc_ssl_certificate_key file | data:key | engine:name:id | store:uri;engine: and store: prefixes, is
interpreted as in ssl_certificate_key, and variables in it work as
described in grpc_ssl_certificate. A key protected by a passphrase is
decrypted with the passphrases from grpc_ssl_password_file.grpc_ssl_ciphers#
openssl ciphers command.grpc_ssl_ciphers directive does not configure TLS 1.3
ciphers; set them with the Ciphersuites command of the
grpc_ssl_conf_command directive instead. The grpc_ssl_ciphers directive ignores
TLS 1.3 cipher names in its value, so such names do not restrict TLS 1.3 connections.
If the value consists only of such names, for example
TLS_AES_128_GCM_SHA256, the configuration fails to load with
the no cipher match error.grpc_ssl_ciphers.grpc_ssl_conf_command#
Ciphersuites command, which sets TLS 1.3 ciphers, requires
OpenSSL 1.1.1 or higher.grpc_ssl_crl#
grpc_ssl_name#
grpc_ssl_name name;grpc_ssl_name `host name from grpc_pass;`grpc_ssl_password_file#
grpc_ssl_protocols#
grpc_ssl_protocols SSLv2 | SSLv3 | TLSv1 | TLSv1.1 | TLSv1.2 | TLSv1.3 ...;grpc_ssl_protocols TLSv1.2 TLSv1.3;grpc_ssl_server_name#
grpc_ssl_session_reuse#
grpc_ssl_session_reuse on | off;grpc_ssl_session_reuse on;SSL3_GET_FINISHED:digest check failed error appears in the logs, try disabling session reuse.grpc_ssl_trusted_certificate#
grpc_ssl_verify#
grpc_ssl_verify_depth#