1. 反向代理配置
Syntax: | proxy_pass |
---|---|
Default: | — |
Context: | location , if in location , limit_except |
Sets the protocol and address of a proxied server and an optional URI to which a location should be mapped. As a protocol, “http
” or “https
” can be specified. The address can be specified as a domain name or IP address, and an optional port:
proxy_pass http://localhost:8000/uri/;
or as a UNIX-domain socket path specified after the word “unix
” and enclosed in colons:
proxy_pass http://unix:/tmp/backend.socket:/uri/;
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.
2. 代理服务器组配置
Syntax: | upstream |
---|---|
Default: | — |
Context: | http |
Defines a group of servers. Servers can listen on different ports. In addition, servers listening on TCP and UNIX-domain sockets can be mixed.
3. 代理服务器配置
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 optional port, or as a UNIX-domain socket path specified after the “unix:
” prefix. If a port is not specified, the port 80 is used. 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 active 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.
If
idle keepalive connections, multiple
workers, and the
shared memory are enabled, the total number of active and idle connections to the proxied server may exceed the
max_conns
value.
Since version 1.5.9 and 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 the fail_timeout
parameter. By default, the number of unsuccessful attempts is set to 1. The zero value disables the accounting of attempts. What is considered an unsuccessful attempt is defined by the proxy_next_upstream, fastcgi_next_upstream, uwsgi_next_upstream, scgi_next_upstream, memcached_next_upstream, and grpc_next_upstream directives.
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.
By default, the parameter is set to 10 seconds.
backup
marks the server as a backup server. It will be passed requests when the primary servers are unavailable.
The parameter cannot be used along with the hash, ip_hash, and random load balancing methods.
Reference:
1. https://nginx.org/en/docs/http/load_balancing.html
2. https://nginx.org/en/docs/http/ngx_http_upstream_module.html