I want to use an instance running Apache or NGINX as my backend server for Elastic Load Balancing (ELB). What settings should I use for the best performance?

The best settings for a load balancer depend on your use case. For the best performance, you must analyze the response times of your backend application and the requirements of your clients.

If the backend is running Apache or NGINX, the following parameters can influence request handling.
Note: After you update your configuration, restart Apache or NGINX.

Client header timeout (Timeout in Apache; client_header_timeout in NGINX)
Set your application timeout to a higher value than the idle timeout value of the load balancer to be sure that the load balancer properly closes down idle connections. If the backend server terminates a connection without proper notification to the load balancer, you might receive a 504 error.

Keep-alives (KeepAlive in Apache; keepalive_disable in NGINX)
Turn on keep-alives to reduce CPU utilization and improve response time. With keep-alives on, the load balancer doesn't need to establish a new TCP connection for every HTTP request.

Keep-alive timeout (KeepAliveTimeout in Apache; keepalive_timeout in NGINX)
When the keep-alive option is enabled, choose a longer keep-alive timeout than the application timeout.

Read timeouts (RequestReadTimeout in Apache; client_header_timeout and client_body_timeout in NGINX)
Set read timeouts that fit your application response times so that your load balancer keeps the connection open long enough to receive both the header and body of the request.

Warning: Be sure that the load balancer idle timeout value is lower than the backend timeout.

Maximum number of keep-alive requests (MaxKeepAliveRequests in Apache; keepalive_requests in NGINX)
This option sets how many requests a single TCP connection serves when keep-alives are on. For optimal usage of resources, set the maximum number of keep-alive requests to 100 or higher.

AcceptFilter (AcceptFilter in Apache; accept_filter in NGINX)
AcceptFilter is enabled by default, and instructs Apache to use the TCP_DEFER_ACCEPT option for the connections. This setting can cause the TCP socket to be in a "half-open" state, where the load balancer believes that the connection is established, but the backend instance does not have the connection established. Half-open connections are more common in low-volume load balancers, where connections have time to age before being used.

Enable the %{X-Forwarded-For}i option so that Apache displays the ELB x-forwarded-for header in its logs for each request. This header contains the IP address of the original client. The %D option adds the time it takes to complete each request to the access logs:

LogFormat "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %b %D \"%{Referer}i\" \"%{User-Agent}i\"" combined

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2016-07-19

Updated: 2018-07-31