uwsgi_socket_keepalive
The `uwsgi_socket_keepalive` directive enables or disables socket keepalive on the uWSGI socket connection to improve reliability.
Description
The uwsgi_socket_keepalive directive is used within NGINX configurations to control whether keepalive functionality is enabled on uWSGI socket connections. When keepalive is enabled, NGINX sends periodic keepalive probes over the socket to ensure that the connection remains active, preventing it from being closed due to inactivity. This is particularly useful in environments where long-lived uWSGI connections might otherwise time out before an HTTP request is fully processed.
The directive accepts a boolean flag as an argument. Setting it to 'on' enables keepalive for uWSGI connections, while setting it to 'off' disables this feature. By default, keepalive is disabled (off). Enabling keepalive can lead to better performance and reliability, especially in high-traffic applications where connections are frequently reused. However, it’s important to note that not all server or network configurations respond well to keepalive settings, and it might require careful tuning to achieve optimal results.
This directive can be set at the http, server, or location contexts, allowing for flexibility in configuration according to the needs of your application. It is generally recommended to test Keepalive connections under load to ensure that they provide the desired benefits without negatively impacting application performance or behavior.
Config Example
location /app {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_socket_keepalive on;
}Ensure that your uWSGI server supports keepalive connections; socket configuration may need adjustments.
Test application performance both with and without keepalive to determine the best configuration for your workload.