Syntax: | server |
---|---|
Default: | — |
Context: | upstream |
Defines the address
and other parameters
of a server. The address can be specified as a domain name or IP address with an obligatory port, or as a UNIX-domain socket path specified after the “unix:
” prefix. A domain name that resolves to several IP addresses defines multiple servers at once.
The following parameters can be defined:
-
weight
=number
- sets the weight of the server, by default, 1.
-
max_conns
=number
- limits the maximum
number
of simultaneous connections to the proxied server (1.11.5). Default value is zero, meaning there is no limit. If the server group does not reside in the shared memory, the limitation works per each worker process.Prior to version 1.11.5, this parameter was available as part of our commercial subscription.
-
max_fails
=number
- sets the number of unsuccessful attempts to communicate with the server that should happen in the duration set by the
fail_timeout
parameter to consider the server unavailable for a duration also set by thefail_timeout
parameter. By default, the number of unsuccessful attempts is set to 1. The zero value disables the accounting of attempts. Here, an unsuccessful attempt is an error or timeout while establishing a connection with the server. -
fail_timeout
=time
- sets
- the time during which the specified number of unsuccessful attempts to communicate with the server should happen to consider the server unavailable;
- and the period of time the server will be considered unavailable.
-
backup
- marks the server as a backup server. Connections to the backup server will be passed when the primary servers are unavailable.
-
down
- marks the server as permanently unavailable.
Additionally, the following parameters are available as part of our commercial subscription:
-
resolve
- monitors changes of the IP addresses that correspond to a domain name of the server, and automatically modifies the upstream configuration without the need of restarting nginx. The server group must reside in the shared memory.
In order for this parameter to work, the resolver directive must be specified in the stream block. Example:
stream { resolver 10.0.0.1; upstream u { zone ...; ... server example.com:12345 resolve; } }
-
service
=name
- enables resolving of DNS SRV records and sets the service
name
(1.9.13). In order for this parameter to work, it is necessary to specify the resolve parameter for the server and specify a hostname without a port number.If the service name does not contain a dot (“
.
”), then the RFC-compliant name is constructed and the TCP protocol is added to the service prefix. For example, to look up the_http._tcp.backend.example.com
SRV record, it is necessary to specify the directive:server backend.example.com service=http resolve;
If the service name contains one or more dots, then the name is constructed by joining the service prefix and the server name. For example, to look up the
_http._tcp.backend.example.com
andserver1.backend.example.com
SRV records, it is necessary to specify the directives:server backend.example.com service=_http._tcp resolve; server example.com service=server1.backend resolve;
Highest-priority SRV records (records with the same lowest-number priority value) are resolved as primary servers, the rest of SRV records are resolved as backup servers. If the backup parameter is specified for the server, high-priority SRV records are resolved as backup servers, the rest of SRV records are ignored.
-
slow_start
=time
- sets the
time
during which the server will recover its weight from zero to a nominal value, when unhealthy server becomes healthy, or when the server becomes available after a period of time it was considered unavailable. Default value is zero, i.e. slow start is disabled.The parameter cannot be used along with the hash load balancing method.
If there is only a single server in a group,max_fails
,fail_timeout
andslow_start
parameters are ignored, and such a server will never be considered unavailable.
Please login to continue.