ajp_connect_timeout

The `ajp_connect_timeout` directive sets the timeout for connections to an AJP backend server.

Syntaxajp_connect_timeout time;
Default60s
Contexthttp, server, location
Arguments1

Description

The ajp_connect_timeout directive is used in NGINX configurations where AJP (Apache JServ Protocol) is utilized to communicate with an AJP backend, such as a Tomcat server. This directive specifies the maximum time that NGINX will wait while trying to establish a connection with the AJP backend server. The timeout is particularly important in high-performance scenarios where delays in connecting to the backend can lead to degraded user experiences and overall performance issues.

When this directive is set, if NGINX cannot successfully connect to the AJP backend server within the specified duration, it will stop trying and return an error response to the client. This is crucial for avoiding long delays for users if the backend is down or slow to respond. The value of the timeout can be defined in seconds or using a time suffix (e.g., '30s' for 30 seconds). This directive should be configured carefully based on the expected latency of the backend server and the overall performance requirements of your application.

The ajp_connect_timeout directive is often used in conjunction with other AJP-related directives, such as ajp_pass, to ensure that all aspects of AJP connections are properly configured for optimal performance. When adjusting this directive, it’s essential to consider the trade-offs between responsiveness and the risk of prematurely terminating connections that may have valid delays due to processing loads on the backend server.

Config Example

# Example NGINX configuration with AJP connection timeout
http {
    upstream tomcats {
        server 127.0.0.1:8009;
        keepalive 10;
    }

    server {
        listen 80;

        location / {
            ajp_pass tomcats;
            ajp_connect_timeout 30s;
            ajp_keep_conn on;
        }
    }
}

Setting the timeout too low may cause premature connection failures and errors.

If the AJP backend is experiencing intermittent latency, a longer timeout may be required to avoid unnecessary disconnections.

This directive must be set in the same context where ajp_pass is defined.

← Back to all directives