ajp_keep_conn

The `ajp_keep_conn` directive enables persistent connections to AJP backends in NGINX.

Syntaxajp_keep_conn on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The ajp_keep_conn directive is utilized in NGINX to control whether to keep connections to the AJP (Apache JServ Protocol) backends persistent. When set to 'on', this directive allows NGINX to maintain and reuse connections to backend servers, as opposed to closing them after each request. This can significantly enhance the performance of applications that employ AJP by reducing the overhead associated with establishing new connections for every request.

By enabling persistent connections, you decrease latency and improve throughput, as the connection setup cost (which includes establishing TCP connections and possibly SSL handshakes) is incurred only once. However, it is important to consider the implications on connection limits set by the backend AJP server. If too many clients attempt to utilize a limited number of backend connections, you can run into issues such as connection refusal or excessive delays. Thus, configuration should be tested for the specific workload characteristics of your application.

The directive can be applied in various contexts, such as http, server, or location blocks in the NGINX configuration, making it flexible for different routing setups. It acts as a simple flag to toggle the behavior of connection handling for AJP communications.

Config Example

http {
	upstream tomcats {
		server 127.0.0.1:8009;
		keepalive 10;
	}

	server {
		listen 80;

		location / {
			ajp_keep_conn on;
			ajp_pass tomcats;
		}
	}
}

Setting ajp_keep_conn on can lead to connection exhaustion if the backend server cannot handle multiple persistent connections effectively.

If connection pooling settings on the backend are lower than the expected concurrent connections from NGINX, it can lead to connection denial errors.

← Back to all directives