proxy_responses

The proxy_responses directive controls the number of responses the NGINX Stream module will accept from upstream servers before closing the connection.

Syntaxproxy_responses number;
Defaultnone
Contextstream, stream server
Arguments1

Description

The proxy_responses directive is used within the stream context in NGINX to specify how many responses are permitted from upstream server(s) before NGINX closes the connection. This directive is particularly useful when dealing with TCP/UDP traffic, where maintaining a robust communication channel with the upstream server is essential for performance and reliability. If you set a specific integer as an argument to this directive, NGINX will keep track of the number of responses received and, once the specified limit is reached, it will close the connection automatically. This can help in scenarios where the upstream servers are known to provide a limited response volume or for implementing certain rates of response handling.

When using proxy_responses, the behavior can be controlled simply by choosing a number that aligns with your requirements. If, for example, you anticipate a high number of server responses at peak loads, setting this directive to a higher number might be beneficial. On the other hand, a lower number can ensure connections don’t remain open longer than necessary, minimizing resource usage. It is crucial to consider the nature of the protocol and connection patterns with the upstream service when configuring this directive, as closing connections prematurely can result in unnecessary retransmissions or dropped packets.

Config Example

stream {
    upstream my_upstream {
        server backend1.example.com:1234;
        server backend2.example.com:1234;
    }

    server {
        listen 1234;
        proxy_pass my_upstream;
        proxy_responses 5;
    }
}

Remember that setting the number too low might cause effective responses to be dropped due to premature connection closures.

High values can lead to resource exhaustion if connections remain open for too long without being properly handled.

← Back to all directives