Proxy#
Allows passing requests to another (proxied) server.
When building from the source code, the module is built by
default; it can be disabled with the build option
--without-http_proxy_module.
In packages and images from our repositories, the module is included in the build.
Related guides
First Steps: proxies requests to a local app.
Runtime Control: a cache zone with
file=survives restarts.Connection Handling: proxying and the WebSocket timeout.
Load Balancing: proxy_next_upstream sets the retry conditions.
Console Light Web Panel: cache zones fill the Caches tab.
Configuration Example#
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache cache_zone;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
}
Directives#
proxy_bind#
Makes outgoing connections to a proxied 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 proxy_bind directive inherited from the previous configuration level, which allows the system to auto-assign the local IP address and port.
By default, this value is evaluated once when the request is initialized, before
a proxied server is selected. In Angie PRO, evaluation happens after each
proxied server selection (including retries), so the bind address can depend on
the selected server; for example, via the $upstream_current_addr
variable. If the evaluated value is empty, no binding is made.
The transparent parameter allows outgoing connections to a proxied
server originate from a non-local IP address, for example, from a real IP
address of a client:
proxy_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.
Note
It is necessary to configure kernel routing table to intercept network traffic from the proxied server.
proxy_buffer_size#
Sets the size of the buffer used for reading the first part of the response received from the proxied server. This part usually contains a small response header. By default, the buffer size is equal to one memory page. This is either 4K or 8K, depending on a platform. It can be made smaller, however.
proxy_buffering#
Enables or disables buffering of responses from the proxied server.
| Angie sends the response to the client in parallel with reading it from the proxied server; the client does not wait for the whole response. The response is read into the buffers set by the proxy_buffer_size and proxy_buffers directives. A buffer is passed for sending once it is completely filled, and the total size of the buffers busy sending is limited by proxy_busy_buffers_size. A partially filled buffer waits until it fills up or the response ends, so data normally reaches the client in whole buffers. Responses that must reach the client as they are produced therefore need |
| Every portion of data read from the proxied server is passed to the client immediately, with no minimum size: 10 bytes read from a 4K buffer are sent right away. Angie uses a single buffer, set by the proxy_buffer_size directive, so it reads no more than that size at a time. No temporary file is used, so responses are neither cached nor stored on disk, and neither proxy_limit_rate nor limit_rate has any effect. |
Buffering can also be enabled or disabled by passing "yes" or "no" in the X-Accel-Buffering response header field. This capability can be disabled using the proxy_ignore_headers directive.
proxy_buffers#
Sets the number and size of the buffers used for reading a response from the proxied server, for a single connection.
By default, the buffer size is equal to one memory page. This is either 4K or 8K, depending on a platform.
proxy_busy_buffers_size#
| |
Default |
|
http, server, location |
When buffering of responses from the proxied server is enabled, limits the total size of buffers that can be busy sending a response to the client while the response is not yet fully read. In the meantime, the rest of the buffers can be used for reading the response and, if needed, buffering part of the response to a temporary file.
By default, size is limited by the size of two buffers set by the proxy_buffer_size and proxy_buffers directives.
proxy_cache#
Defines a shared memory zone used for caching. The same zone can be used in several places. Parameter value can contain variables.
| disables caching inherited from the previous configuration level. |
In Angie PRO, you can specify multiple proxy_cache_path directives that
use the same keys_zone value to enable cache sharding. When doing so,
you should set the path parameter of the proxy_cache directive
that uses this keys_zone value:
| The value is evaluated at the time of caching the response from the backend and is expected to use variables, including those containing information from the response. If the response is taken from the cache, the path is not reevaluated; thus, a cached response retains its original path until it is removed from the cache. |
This allows selecting the needed cache path by applying map directives or
scripts to responses from the backend. Example for Content-Type:
proxy_cache_path /cache/one keys_zone=zone:10m;
proxy_cache_path /cache/two keys_zone=zone;
map $upstream_http_content_type $cache {
~^text/ one;
default two;
}
server {
...
location / {
proxy_pass http://backend;
proxy_cache zone path=/cache/$cache;
proxy_cache_valid 200 10m;
}
}
Here there are two cache paths and a variable mapping to distinguish between them.
If Content-Type starts with text/, the first path will be chosen,
otherwise the second.
Note
When using proxy_cache, you typically need to also set the proxy_cache_valid directive to explicitly specify the caching time for responses. If it's not set, Angie doesn't use default values but determines the response caching time based on HTTP response headers from the server in the following priority order:
The
X-Accel-Expiresheader (highest priority).The
Cache-Controlheader withmax-ageors-maxageparameters.The
Expiresheader.
If none of these headers contain valid values or are not present at all, the response will not be cached because its expiration time cannot be determined.
proxy_cache_background_update#
| |
Default |
|
http, server, location |
Allows starting a background subrequest to update an expired cache item, while a stale cached response is returned to the client.
Warning
The use of a stale cached response while it's being updated must be allowed.
proxy_cache_bypass#
Defines conditions under which the response will not be taken from cache. If at least one value of the string parameters is not empty and is not equal to "0", then the response will not be taken from cache:
proxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
proxy_cache_bypass $http_pragma $http_authorization;
Parameter values can contain variables.
Can be used together with the proxy_no_cache directive.
proxy_cache_convert_head#
| |
Default |
|
http, server, location |
Enables or disables the conversion of the "HEAD" method to "GET" for caching. If conversion is disabled, the cache key must include the $request_method.
proxy_cache_key#
| |
Default |
|
http, server, location |
Defines a key for caching. The key can contain variables. For example,
proxy_cache_key "$host$request_uri $cookie_user";
By default, the directive's value is close to the string
proxy_cache_key $scheme$proxy_host$uri$is_args$args;
proxy_cache_lock#
When enabled, only one request at a time will be allowed to populate a new cache element identified according to the proxy_cache_key directive by passing a request to the proxied server. Other requests for the same cache element will either wait for a response to appear in cache or for the cache lock for this element to be released, up to the time set by the proxy_cache_lock_timeout directive.
proxy_cache_lock_age#
If the last request passed to the proxied server for populating a new cache element has not completed for the specified time, one more request may be passed to the proxied server.
proxy_cache_lock_timeout#
| |
Default |
|
http, server, location |
Sets a timeout for proxy_cache_lock. When the time expires, the request will be passed to the proxied server, however, the response will not be cached.
proxy_cache_max_range_offset#
Sets an offset in bytes for byte-range requests. If the range is beyond the specified offset, the range request will be passed to the proxied server and the response will not be cached.
proxy_cache_methods#
| |
Default |
|
http, server, location |
If the client request method is listed in this directive, then the response will be cached. "GET" and "HEAD" methods are always added to the list, but it is recommended to specify them explicitly. See also the proxy_no_cache directive.
proxy_cache_min_uses#
Sets the number of requests after which the response will be cached.
Warning
Cache metadata is stored in shared memory. Manually deleting cache files does not reset the counters and may lead to unpredictable behavior. For a complete reset, stop the server, delete the cache directory, and start again.
Note
Third-party cache purge modules (for example, Cache Purge) only delete
files but do not reset the proxy_cache_min_uses counter. The directive
is intended to protect the cache from pollution by infrequent requests, and resetting
the counter on purge may negatively affect performance.
proxy_cache_path#
| |
Default | — |
http |
Sets the path and other parameters of a cache. Cache data are stored in files. The file name in a cache is a result of applying the MD5 function to the cache key.
| defines hierarchy levels of a cache: from 1 to 3, each level accepts values 1 or 2. |
For example, in the following configuration:
proxy_cache_path /data/angie/cache levels=1:2 keys_zone=one:10m;
file names in a cache will look like this:
/data/angie/cache/c/29/b7f54b2df7773722d382f4809d65029c
A cached response is first written to a temporary file, and then the file is renamed. Temporary files and the cache can be put on different file systems. However, be aware that in this case a file is copied across two file systems instead of the cheap renaming operation. It is thus recommended that for any given location both cache and a directory holding temporary files are put on the same file system.
| determines the directory to be used for temporary files |
| If the parameter is not specified or set to |
| temporary files will be placed directly in the cache directory |
| Sets the name and size of the shared memory zone for storing all active keys and information about data. Cache metadata is stored in shared memory. The zone size is specified in bytes and must be at least two system
memory pages. The A zone of 1 megabyte is sufficient to store about 8000 keys. When an optional file is specified with If the file has incompatible content, for example because an
incompatible build wrote it, Angie renames it with the If the zone size in the configuration no longer matches the size saved
in the file, the configuration fails to load until the file is removed
or the original size is restored. The configuration also fails to load
if the zone cannot be mapped at the memory address saved in the file:
Angie logs Warning Make sure the path to the file is specified correctly and has the necessary access permissions for Angie to use, and is protected from unauthorized access; relative paths are based on the prefix. |
| If cached data is not accessed within the time set by this parameter, it is removed, regardless of its freshness; each access resets this timer. This differs from the size-based eviction performed by the cache manager described below: inactivity-based removal applies even when the cache is below By default, |
Note
In Angie PRO, multiple proxy_cache_path directives can be specified with the same
keys_zone value. The shared memory zone size can only be
specified in the first one. Selection between directives will be
made based on the path parameter of the corresponding
proxy_cache directive.
A special cache manager process monitors the maximum cache size and the minimum amount of free space on the filesystem with the cache, and removes the least recently used data when the maximum cache size is exceeded or there is insufficient free space. Data removal occurs in iterations.
| maximum threshold value for cache size The value is specified in bytes; the |
| minimum threshold value for free space on the file system with the cache The value is specified in the same units as On platforms that do not support querying file system statistics,
the parameter is ignored, and Angie logs the warning
|
| maximum number of cache items to be removed in one iteration By default: |
| limits the duration of one iteration By default: |
| configures a pause between iterations By default: |
One minute after Angie starts, a special cache loader process is activated.
It scans the filesystem for previously cached data
and loads this information into the cache zone.
This process works iteratively;
each iteration processes a limited number of items specified by the loader_files parameter,
ensures it doesn't exceed loader_threshold,
then takes a short pause defined by loader_sleep
before moving to the next batch.
Iterations continue
until the loader has processed all existing cache entries on disk:
| maximum number of cache items to load in one iteration By default: |
| limits the duration of one iteration By default: |
| configures a pause between iterations By default: |
Note
A zone restored from the file of the keys_zone parameter keeps
the cache keys it held when Angie saved it. If the cache loader had
finished by then, it does not scan the cache directory again, and the zone
is complete as soon as Angie starts. If Angie stopped before the loader
started, that is, within the first minute after a start, the loader fills
the restored zone as described above.
If Angie stops while the loader is still running, a graceful shutdown
(angie -s quit) waits for the loader to finish. A fast shutdown
that signals only the master process, such as angie -s stop or
docker stop, interrupts the loader instead. The loader then does
not resume after the restart, and the restored zone stays incomplete; its
cold field in the /status/http/caches/ API section stays true. To have the
loader rebuild such a zone, delete the file before starting Angie. If the
loader process receives the signal itself, for example when the signal is
sent to every Angie process, it stops cleanly and scans the cache directory
again after the restart.
proxy_cache_revalidate#
| |
Default |
|
http, server, location |
Enables revalidation of expired cache items using conditional requests with the If-Modified-Since and If-None-Match header fields.
proxy_cache_use_stale#
| |
Default |
|
http, server, location |
Determines in which cases a stale cached response can be used. The directive parameters match those of the proxy_next_upstream directive.
| permits using a stale cached response if a proxied server to process a request cannot be selected. |
| additional parameter, permits using a stale cached response if it is currently being updated. This allows minimizing the number of accesses to proxied servers when updating cached data. |
| permits using a stale cached response if a request with a non-idempotent method has already been sent to a proxied server and communication with that server then fails for any reason; of the non-idempotent methods only |
Using a stale cached response can also be enabled directly in the response header for a specified number of seconds after the response became stale:
The stale-while-revalidate extension of the
Cache-Controlheader field permits using a stale cached response if it is currently being updated.The stale-if-error extension of the
Cache-Controlheader field permits using a stale cached response in case of an error.
Note
This has lower priority than using the directive parameters.
To minimize the number of accesses to proxied servers when populating a new cache element, the proxy_cache_lock directive can be used.
proxy_cache_valid#
Sets caching time for different response codes. For example, the directives
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
set 10 minutes of caching for responses with codes 200 and 302 and 1 minute for responses with code 404.
If only caching time is specified,
proxy_cache_valid 5m;
then only 200, 301, and 302 responses are cached.
In addition, the any parameter can be specified to cache any responses:
proxy_cache_valid 200 302 10m;
proxy_cache_valid 301 1h;
proxy_cache_valid any 1m;
Note
Parameters of caching can also be set directly in the response header. This has higher priority than setting of caching time using the directive.
The
X-Accel-Expiresheader field sets caching time of a response in seconds. The zero value disables caching for a response. If the value starts with the@prefix, it sets an absolute time in seconds since Epoch, up to which the response may be cached.If the header does not include the
X-Accel-Expiresfield, parameters of caching may be set in the header fieldsExpiresorCache-Control.If the header includes the
Set-Cookiefield, such a response will not be cached.If the header includes the
Varyfield with the special value "*", such a response will not be cached. If the header includes theVaryfield with another value, such a response will be cached taking into account the corresponding request header fields.
Processing of one or more of these response header fields can be disabled using the proxy_ignore_headers directive.
proxy_connect_timeout#
Defines a timeout for establishing a connection with a proxied 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.
proxy_connection_drop#
| |
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
DELETE.
Idle connections in the cache are not affected.
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.
proxy_force_ranges#
Enables byte-range support for both cached and uncached responses from the proxied server regardless of the Accept-Ranges field in these responses.
proxy_headers_hash_bucket_size#
| |
Default |
|
http, server, location |
Sets the bucket size for hash tables used by the proxy_hide_header and proxy_set_header directives. The details of setting up hash tables are provided separately.
proxy_headers_hash_max_size#
| |
Default |
|
http, server, location |
Sets the maximum size of hash tables used by the proxy_hide_header and proxy_set_header directives. The details of setting up hash tables are provided separately.
proxy_hide_header#
By default, Angie does not pass the header fields Date, Server, X-Pad, and X-Accel-... from the response of a proxied server to a client. The proxy_hide_header directive sets additional fields that will not be passed. If, on the contrary, the passing of fields needs to be permitted, the proxy_pass_header directive can be used.
proxy_http3_hq#
Toggles the special hq-interop negotiation mode,
which is used for
QUIC
interop tests
that Angie relies on.
Warning
Enable this mode only to run specialized tests that explicitly require it.
proxy_http3_max_concurrent_streams#
| |
Default |
|
http, server, location |
Initializes HTTP/3 and QUIC settings and sets the maximum number of concurrent HTTP/3 request streams in a connection. Requires enabling keepalive connections.
proxy_http3_max_table_capacity#
| |
Default |
|
http, server, location |
Sets the dynamic table capacity for proxy connections.
Note
A similar directive http3_max_table_capacity sets this value for server connections. To avoid errors, dynamic table usage is disabled when caching is enabled in proxy mode.
proxy_http3_stream_buffer_size#
| |
Default |
|
http, server, location |
Sets the size of the buffer used for reading and writing QUIC streams.
proxy_http_version#
| |
Default |
|
http, server, location, if in location, limit_except |
Sets the HTTP protocol version for proxying. Version 1.1 or higher is recommended for use with keepalive connections.
proxy_ignore_client_abort#
| |
Default |
|
http, server, location |
Determines whether the connection with a proxied server should be closed when a client closes the connection without waiting for a response.
proxy_ignore_headers#
Disables processing of certain response header fields from the proxied server. The following fields can be ignored: X-Accel-Redirect, X-Accel-Expires, X-Accel-Limit-Rate, X-Accel-Buffering, X-Accel-Charset, Expires, Cache-Control, Set-Cookie, and Vary.
If not disabled, processing of these header fields has the following effect:
X-Accel-Expires,Expires,Cache-Control,Set-Cookie, andVaryset the parameters of response caching;X-Accel-Redirectperforms an internal redirect to the specified URI or named location;X-Accel-Limit-Ratesets the rate limit for transmission of a response to a client;X-Accel-Bufferingenables or disables buffering of a response;X-Accel-Charsetsets the desired charset of a response.
proxy_intercept_errors#
| |
Default |
|
http, server, location |
Determines whether proxied 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.
proxy_limit_rate#
Limits the speed of reading the response from the proxied server. The rate is specified in bytes per second and can contain variables.
| disables rate limiting |
Note
The limit is set per a request, so if Angie simultaneously opens two connections to the proxied server, the overall rate will be twice as much as the specified limit. The limitation works only if buffering of responses from the proxied server is enabled.
proxy_max_temp_file_size#
| |
Default |
|
http, server, location |
When buffering of responses from the proxied server is enabled, and the whole response does not fit into the buffers set by the proxy_buffer_size and proxy_buffers directives, a part of the response can be saved to a temporary file. This directive sets the maximum size of the temporary file. The size of data written to the temporary file at a time is set by the proxy_temp_file_write_size directive.
| disables buffering of responses to temporary files |
proxy_method#
Specifies the HTTP method to use in requests forwarded to the proxied server instead of the method from the client request. Parameter value can contain variables.
proxy_next_upstream#
| |
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. |
If all upstream servers are unavailable or return a response with a status
considered an error by proxy_next_upstream, Angie returns its own
standard error page instead of the response body from the last upstream server.
Note
It should be understood 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.
| are always considered unsuccessful attempts, even if they are not specified in the directive |
| are considered unsuccessful attempts only if they are specified in the directive |
| are never considered unsuccessful attempts |
Passing a request to the next server can be limited by the number of tries and by time.
proxy_next_upstream_timeout#
| |
Default |
|
http, server, location |
Limits the time during which a request can be passed to the next server.
| disables this limitation |
proxy_next_upstream_tries#
| |
Default |
|
http, server, location |
Limits the number of possible tries for passing a request to the next server.
| disables this limitation |
proxy_no_cache#
Defines conditions under which the response will not be saved to a cache. If at least one value of the string parameters is not empty and is not equal to "0" then the response will not be saved:
proxy_no_cache $cookie_nocache $arg_nocache$arg_comment;
proxy_no_cache $http_pragma $http_authorization;
Parameter values can contain variables.
Can be used along with the proxy_cache_bypass directive.
proxy_pass#
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.
Note
A domain name in proxy_pass that contains no variables and does not
match a defined server group implicitly creates a
server group of a single server, equivalent to:
upstream example.com {
server example.com;
}
These server group names are shared across the entire http
configuration, regardless of the server block where
proxy_pass appears. Because the implicitly created server
has no resolve parameter, the name is resolved once, at
configuration load time, and the obtained addresses are used until the next
reload, even when a resolver is configured.
As a result, a proxy_pass whose variable evaluates to that same name
reuses this existing server group with its load-time addresses instead of
resolving the name per request through the resolver. To
re-resolve the name at runtime and follow DNS changes, define the server
group explicitly and add the resolve parameter to its
server.
A request URI is passed to the server as follows:
If the
proxy_passdirective is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive:location /name/ { proxy_pass http://127.0.0.1/remote/; }
The server receives a request for
/name/pageas/remote/page.If
proxy_passis specified without a URI, the server receives the request URI with its arguments exactly as the client sent it (the value of $request_uri), provided that Angie has not changed the URI or the arguments before proxying the request. Otherwise, the server receives the current value of $uri, which is the normalized URI, followed by the current arguments. Characters that cannot appear literally in a URI path, such as spaces, are percent-encoded again in this case; the arguments are passed as they are.The URI or the arguments count as changed when:
the regular expression of a rewrite directive matches;
the $args variable is assigned a value, even its current one;
the request is internally redirected to a URI, for example, by the index or error_page directive, by the last parameter of try_files, or by the
X-Accel-Redirectresponse header field.
A redirect to a named location does not change the URI, whether it is made by goto, error_page, try_files, or
X-Accel-Redirect.For example, a client requests
/some/path/%7Euser//a%20b?x=1. In this configuration, the server receives the request URI unchanged:location /some/path/ { proxy_pass http://127.0.0.1; }
In this configuration, the rewrite directive changes the URI:
location /some/path/ { rewrite ^/some/path/(.*)$ /other/$1 break; proxy_pass http://127.0.0.1; }
The server receives
/other/~user/a%20b?x=1:%7Eis decoded, the double slash is merged, and the space is encoded again.
In some cases, the part of a request URI to be replaced cannot be determined:
When
locationis specified using a regular expression, inside a named or combinedlocation, and inside an if or limit_except block.In these cases,
proxy_passwithout variables must be specified without a URI; otherwise, Angie refuses to load the configuration.When the rewrite directive with the
breakflag changes the URI inside the proxiedlocation, so the request stays in that location:location /name/ { rewrite /name/([^/]+) /users?name=$1 break; proxy_pass http://127.0.0.1; }
In this case, the URI specified in the directive is ignored and the full changed request URI is passed to the server.
When variables are used in
proxy_pass:location /name/ { proxy_pass http://127.0.0.1$request_uri; }
In this case, if a URI is specified in the directive, it is passed to the server as is, replacing the original request URI.
WebSocket proxying requires special configuration.
Note
If proxy_pass is placed 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/).
proxy_pass_header#
Permits passing otherwise disabled header fields from a proxied server to a client.
proxy_pass_request_body#
| |
Default |
|
http, server, location |
Indicates whether the original request body is passed to the proxied server.
location /x-accel-redirect-here/ {
proxy_method GET;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_pass ...;
}
See also the proxy_set_header and proxy_pass_request_headers directives.
proxy_pass_request_headers#
| |
Default |
|
http, server, location |
Indicates whether the header fields of the original request are passed to the proxied server.
location /x-accel-redirect-here/ {
proxy_method GET;
proxy_pass_request_headers off;
proxy_pass_request_body off;
proxy_pass ...;
}
See also the proxy_set_header and proxy_pass_request_body directives.
proxy_pass_trailers#
Allows passing trailer fields from a proxied server to a client.
A trailer section in HTTP/1.1 is explicitly enabled.
location / {
proxy_http_version 1.1;
proxy_set_header Connection "te";
proxy_set_header TE "trailers";
proxy_pass_trailers on;
proxy_pass ...;
}
proxy_quic_active_connection_id_limit#
| |
Default |
|
http, server, location |
Sets the QUIC
active_connection_id_limit transport parameter value.
This is the maximum number of active
connection IDs
that can be maintained per server.
proxy_quic_gso#
Toggles sending data in QUIC-optimized batch mode using generic segmentation offload.
proxy_quic_host_key#
Sets a file with the secret key used with QUIC to encrypt Stateless Reset and Address Validation tokens. By default, a random key is generated at each restart. Tokens generated with old keys are not accepted.
proxy_read_timeout#
Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations, not for the transmission of the whole response. If the proxied server does not transmit anything within this time, the connection is closed.
proxy_redirect#
| |
Default |
|
http, server, location |
Sets the text that should be changed in the "Location" and "Refresh" header fields of a proxied server response.
Suppose a proxied server returned the header field:
Location: http://localhost:8000/two/some/uri/
The directive
proxy_redirect http://localhost:8000/two/ http://frontend/one/;
will rewrite this string to:
Location: http://frontend/one/some/uri/
A server name may be omitted in the replacement string:
proxy_redirect http://localhost:8000/two/ /;
then the primary server's name and port, if different from 80, will be inserted.
The default replacement specified by the default parameter uses the parameters of the location and proxy_pass directives. Hence, the two configurations below are equivalent:
location /one/ {
proxy_pass http://upstream:port/two/;
proxy_redirect default;
}
location /one/ {
proxy_pass http://upstream:port/two/;
proxy_redirect http://upstream:port/two/ /one/;
}
Warning
The default parameter is not permitted if proxy_pass is specified using variables.
A replacement string can contain variables:
proxy_redirect http://localhost:8000/ http://$host:$server_port/;
A redirect can also contain variables:
proxy_redirect http://$proxy_host:8000/ /;
The directive can be specified using regular expressions. In this case, redirect should either start with the "~" symbol for a case-sensitive matching, or with the "~*" symbols for case-insensitive matching. The regular expression can contain named and positional captures, and replacement can reference them:
proxy_redirect ~^(http://[^:]+):\d+(/.+)$ $1$2;
proxy_redirect ~*/user/([^/]+)/(.+)$ http://$1.example.com/$2;
Several proxy_redirect directives can be specified on the same level:
proxy_redirect default;
proxy_redirect http://localhost:8000/ /;
proxy_redirect http://www.example.com/ /;
If several directives can be applied to the header fields of a proxied server response, the first matching directive will be chosen.
The off parameter cancels the effect of the proxy_redirect directives inherited from the previous configuration level.
Using this directive, it is also possible to add host names to relative redirects issued by a proxied server:
proxy_redirect / /;
proxy_request_buffering#
| |
Default |
|
http, server, location |
Enables or disables buffering of a client request body.
| the entire request body is read from the client before sending the request to a proxied server. |
| the request body is sent to the proxied server immediately as it is received. In this case, the request cannot be passed to the next server if Angie already started sending the request body. |
When HTTP/1.1 chunked transfer encoding is used to send the original request body, the request body is buffered regardless of the directive value unless HTTP/1.1, HTTP/2, or HTTP/3 is enabled for proxying.
proxy_send_lowat#
If the directive is set to a non-zero value, Angie will try to minimize the number of send operations on outgoing connections to a proxied server by using either NOTE_LOWAT flag of the kqueue method, or the SO_SNDLOWAT socket option, with the specified size.
Note
This directive is ignored on Linux, Solaris, and Windows.
proxy_send_timeout#
Sets a timeout for transmitting a request to the proxied server. The timeout is set only between two successive write operations, not for the transmission of the whole request. If the proxied server does not receive anything within this time, the connection is closed.
proxy_set_body#
Allows redefining the request body passed to the proxied server. The value can contain variables.
proxy_set_header#
| |
Default |
|
http, server, location |
Allows redefining or appending fields to the request header passed to the proxied server. The value can contain variables. These directives are inherited from the previous configuration level if and only if there are no proxy_set_header directives defined on the current level. By default, only two fields are redefined:
proxy_set_header Host $proxy_host;
proxy_set_header Connection close;
If caching is enabled, the header fields If-Modified-Since, If-Unmodified-Since, If-None-Match, If-Match, Range, and If-Range from the original request are not passed to the proxied server.
An unchanged "Host" request header field can be passed like this:
proxy_set_header Host $http_host;
However, if this field is not present in a client request header then nothing will be passed. In such a case it is better to use the $host variable - its value equals the server name in the "Host" request header field or the primary server name if this field is not present:
proxy_set_header Host $host;
In addition, the server name can be passed together with the port of the proxied server:
proxy_set_header Host $host:$proxy_port;
If the value of a header field is an empty string then this field will not be passed to a proxied server:
proxy_set_header Accept-Encoding "";
proxy_socket_keepalive#
| |
Default |
|
http, server, location |
Configures the "TCP keepalive" behavior for outgoing connections to a proxied server.
| By default, the operating system's settings are in effect for the socket. |
| The |
proxy_ssl_certificate#
Specifies the certificate in the PEM format used for authentication to a proxied HTTPS server.
The value is interpreted as in ssl_certificate: a file path, or the PEM
text of the certificate after the data: prefix. The value can contain
variables; they are evaluated each time Angie establishes a connection to the
proxied HTTPS 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 proxy_ssl_certificate_cache.
When proxy_ssl_ntls is enabled, the directive accepts two arguments instead of one:
location /proxy {
proxy_ssl_ntls on;
proxy_ssl_certificate sign.crt enc.crt;
proxy_ssl_certificate_key sign.key enc.key;
proxy_ssl_ciphers "ECC-SM2-WITH-SM4-SM3:ECDHE-SM2-WITH-SM4-SM3:RSA";
proxy_pass https://backend:443;
}
proxy_ssl_certificate_cache#
| |
Default |
|
http, server, location |
Defines a cache that stores SSL certificates and secret keys specified using variables.
The directive supports the following parameters:
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 itsvalidperiod; 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 theengine:orstore:prefix is loaded again; an element specified with thedata:prefix stays valid.off— disables the cache.
Keys protected by a passphrase (see proxy_ssl_password_file) are not cached.
Example:
proxy_ssl_certificate /etc/angie/ssl/$host.crt;
proxy_ssl_certificate_key /etc/angie/ssl/$host.key;
proxy_ssl_certificate_cache max=1000 inactive=20s valid=1m;
proxy_ssl_certificate_key#
| |
Default | — |
http, server, location |
Specifies the secret key in the PEM format used for authentication to a proxied HTTPS server.
The value, including the engine: and store: prefixes, is
interpreted as in ssl_certificate_key, and variables in it work as
described in proxy_ssl_certificate. A key protected by a passphrase is
decrypted with the passphrases from proxy_ssl_password_file.
When proxy_ssl_ntls is enabled, the directive accepts two arguments instead of one:
location /proxy {
proxy_ssl_ntls on;
proxy_ssl_certificate sign.crt enc.crt;
proxy_ssl_certificate_key sign.key enc.key;
proxy_ssl_ciphers "ECC-SM2-WITH-SM4-SM3:ECDHE-SM2-WITH-SM4-SM3:RSA";
proxy_pass https://backend:443;
}
proxy_ssl_ciphers#
Specifies the enabled ciphers for requests to a proxied HTTPS 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 openssl ciphers command.
Warning
With OpenSSL, the proxy_ssl_ciphers directive does not configure TLS 1.3
ciphers; set them with the Ciphersuites command of the
proxy_ssl_conf_command directive instead. The proxy_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.
With LibreSSL, TLS 1.3 ciphers can be configured using
proxy_ssl_ciphers.With BoringSSL, TLS 1.3 ciphers cannot be configured at all.
proxy_ssl_conf_command#
Sets arbitrary OpenSSL configuration commands when establishing a connection with the proxied HTTPS server.
Note
The directive is supported when using OpenSSL 1.0.2 or higher.
The Ciphersuites command, which sets TLS 1.3 ciphers, requires
OpenSSL 1.1.1 or higher.
Several proxy_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 proxy_ssl_conf_command directives defined on the current level.
Warning
Note that configuring OpenSSL directly might result in unexpected behavior.
proxy_ssl_crl#
Specifies a file with revoked certificates (CRL) in the PEM format used to verify the certificate of the proxied HTTPS server.
proxy_ssl_keylog_file#
Added in version 1.12.0.
Specifies a file to log SSL/TLS keys for connections to proxied HTTPS servers in the context, using the SSLKEYLOGFILE format used by tools such as Wireshark to decrypt captured TLS traffic.
The directive should not be used with LibreSSL.
Warning
The file contains sensitive TLS key material that can decrypt captured traffic for the corresponding connections. Use this directive only for debugging or protocol analysis, restrict access to the file, and remove it when no longer needed.
proxy_ssl_name#
Allows overriding the server name used to verify the certificate of the proxied HTTPS server and to be passed through SNI when establishing a connection with the proxied HTTPS server.
The server name can also be specified with variables.
By default, the host part of the proxy_pass URL is used.
proxy_ssl_ntls#
Enables client-side support for NTLS using the Tongsuo TLS library.
location /proxy {
proxy_ssl_ntls on;
proxy_ssl_certificate sign.crt enc.crt;
proxy_ssl_certificate_key sign.key enc.key;
proxy_ssl_ciphers "ECC-SM2-WITH-SM4-SM3:ECDHE-SM2-WITH-SM4-SM3:RSA";
proxy_pass https://backend:443;
}
Note
Angie must be built with the --with-ntls configuration parameter and an SSL library with NTLS support:
$ ./configure --with-openssl=../Tongsuo-8.3.0 \
--with-openssl-opt=enable-ntls \
--with-ntls
proxy_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.
proxy_ssl_protocols#
| |
Default |
|
http, server, location |
Enables the specified protocols for requests to a proxied HTTPS server.
proxy_ssl_server_name#
Enables or disables passing the server name set by the proxy_ssl_name directive via the Server Name Indication TLS extension (SNI, RFC 6066) when establishing a connection with the proxied HTTPS server.
proxy_ssl_session_reuse#
| |
Default |
|
http, server, location |
Determines whether SSL sessions can be reused when working with the proxied server. If the SSL3_GET_FINISHED:digest check failed error appears in the logs, try disabling session reuse.
proxy_ssl_trusted_certificate#
Specifies a file with trusted CA certificates in the PEM format used to verify the certificate of the proxied HTTPS server.
proxy_ssl_verify#
Enables or disables verification of the proxied HTTPS server certificate.
proxy_ssl_verify_depth#
Sets the verification depth in the proxied HTTPS server certificate chain.
proxy_store#
Enables saving of files to a disk.
| saves files according to the paths specified in the alias or root directives |
| disables saving of files |
The file name can be set explicitly using a string with variables:
proxy_store /data/www$original_uri;
The modification time of files is set according to the received Last-Modified header field in the response. The response is first written to a temporary file, and then the file is renamed. The temporary file and the persistent store for the response can be on different file systems. However, be aware that in this case instead of the cheap rename operation within one file system, the file is copied from one file system to another. It is thus recommended that for any given location both saved files and a directory holding temporary files, set by the proxy_temp_path directive, are put on the same file system.
This directive can be used to create local copies of static unchangeable files, e.g.:
location /images/ {
root /data/www;
error_page 404 = /fetch$uri;
}
location /fetch/ {
internal;
proxy_pass http://backend/;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
proxy_temp_path /data/temp;
alias /data/www/;
}
or like this:
location /images/ {
root /data/www;
error_page 404 = @fetch;
}
location @fetch {
internal;
proxy_pass http://backend;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
proxy_temp_path /data/temp;
root /data/www;
}
proxy_store_access#
| |
Default |
|
http, server, location |
Sets access permissions for newly created files and directories, e.g.:
proxy_store_access user:rw group:rw all:r;
If any group or all access permissions are specified, then user permissions may be omitted:
proxy_store_access group:rw all:r;
proxy_temp_file_write_size#
| |
Default |
|
http, server, location |
Limits the size of data written to a temporary file at a time, when buffering of responses from the proxied server to temporary files is enabled. By default, size is limited by two buffers set by the proxy_buffer_size and proxy_buffers directives. The maximum size of a temporary file is set by the proxy_max_temp_file_size directive.
proxy_temp_path#
| |
Default |
|
http, server, location |
Defines a directory for storing temporary files with data received from proxied servers. Up to three-level subdirectory hierarchy can be used underneath the specified directory. For example, in the following configuration
proxy_temp_path /spool/angie/proxy_temp 1 2;
a temporary file might look like this:
/spool/angie/proxy_temp/7/45/00000123457
See also the use_temp_path parameter of the proxy_cache_path directive.
Built-in Variables#
The module supports built-in variables that can be used to compose headers using the proxy_set_header directive: the name and port of a proxied server as specified in the proxy_pass directive; port of a proxied server as specified in the proxy_pass directive, or the protocol's default port;$proxy_add_x_forwarded_for#X-Forwarded-For client request header field with the $remote_addr variable appended to it, separated by a comma. If the X-Forwarded-For field is not present in the client request header, the $proxy_add_x_forwarded_for variable is equal to the $remote_addr variable.$proxy_host#$proxy_port#