• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Nginx Tip – Configure a keepalive disable with keepalive_disable

December 19, 2023

Nginx Tip – Configure a keepalive disable with keepalive_disable

Nginx is a popular web server and reverse proxy server that is known for its high performance, scalability, and flexibility. It is widely used by many websites and web applications to handle a large number of concurrent connections efficiently. One of the features that contribute to Nginx’s performance is its ability to keep connections alive, known as keepalive.

By default, Nginx enables keepalive connections to improve performance by allowing multiple requests to be sent over a single TCP connection. This reduces the overhead of establishing new connections for each request, resulting in faster response times and reduced server load.

However, there may be situations where you want to disable keepalive connections for specific requests or for the entire server. This can be useful in scenarios where you want to conserve server resources, prevent idle connections from consuming resources, or troubleshoot certain issues.

Using the keepalive_disable Directive

Nginx provides the keepalive_disable directive that allows you to selectively disable keepalive connections based on various conditions. This directive can be used in the http, server, or location context to specify when keepalive should be disabled.

The keepalive_disable directive accepts a list of conditions that determine when keepalive connections should be disabled. Some of the commonly used conditions include:

  • none: Disables keepalive for all requests.
  • msie6: Disables keepalive for requests from Internet Explorer 6.
  • safari: Disables keepalive for requests from Safari.
  • android: Disables keepalive for requests from Android devices.
  • invalid_header: Disables keepalive for requests with invalid headers.

For example, to disable keepalive for all requests, you can use the following configuration:

http {
  keepalive_disable none;
}

If you want to disable keepalive only for requests from Internet Explorer 6, you can use:

http {
  keepalive_disable msie6;
}

Similarly, you can combine multiple conditions to disable keepalive based on specific requirements.

Benefits of Disabling Keepalive

While keepalive connections offer performance benefits in most cases, there are situations where disabling keepalive can be advantageous:

  • Resource Conservation: Disabling keepalive can help conserve server resources, especially in scenarios where there are a large number of idle connections consuming memory and other resources.
  • Connection Troubleshooting: Disabling keepalive can be useful when troubleshooting certain connection-related issues, such as connection resets or timeouts.
  • Security: Disabling keepalive can help mitigate certain security risks, such as slowloris attacks, where an attacker keeps multiple connections open to exhaust server resources.

It is important to note that disabling keepalive may have an impact on performance, especially for websites with high traffic or frequent requests. Therefore, it is recommended to carefully evaluate the need for disabling keepalive and monitor the performance impact.

Conclusion

The keepalive_disable directive in Nginx provides a flexible way to disable keepalive connections based on various conditions. By selectively disabling keepalive, you can conserve server resources, troubleshoot connection issues, and enhance security. However, it is crucial to assess the impact on performance before disabling keepalive for the entire server or for critical requests.

For more information about VPS hosting and how it can benefit your website or web application, consider exploring Server.HK. With their top-notch VPS solutions, you can experience high performance, reliability, and scalability for your hosting needs.

Recent Posts

  • How to Install CentOS 9 Step-by-Step
  • What Is CentOS? A Complete Beginner’s Guide to CentOS Linux in 2026
  • Debian Server Troubleshooting Checklist
  • How to Configure a Firewall on a Debian Server: Theory and Best Practices
  • Debian Boot Process Explained

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot