• 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 – Optimize keepalive timeout with keepalive_timeout

December 19, 2023

Nginx Tip – Optimize keepalive timeout with keepalive_timeout

When it comes to optimizing the performance of your website, every little tweak can make a big difference. One often overlooked aspect is the keepalive timeout setting in Nginx. In this article, we will explore what keepalive timeout is, why it is important, and how to optimize it using the keepalive_timeout directive.

Understanding Keepalive Timeout

Keepalive timeout refers to the duration for which a connection between the client and the server remains open after a request has been processed. By keeping the connection open, subsequent requests from the same client can be served faster, as there is no need to establish a new connection each time.

However, keeping connections open indefinitely can lead to resource wastage, as idle connections consume server resources. Therefore, it is crucial to find the right balance between keeping connections open for faster response times and closing idle connections to free up resources.

The Importance of Optimizing Keepalive Timeout

Optimizing keepalive timeout can have a significant impact on the performance of your website. Here are a few reasons why it is important:

  • Reduced Latency: By keeping connections open, subsequent requests can be served faster, reducing the overall latency experienced by users.
  • Improved Scalability: With optimized keepalive timeout, your server can handle a larger number of concurrent connections, improving the scalability of your website.
  • Resource Efficiency: Closing idle connections frees up server resources, allowing them to be utilized for serving other requests.

Optimizing Keepalive Timeout with keepalive_timeout

In Nginx, the keepalive timeout can be optimized using the keepalive_timeout directive. This directive allows you to specify the duration for which a connection should be kept open after a request has been processed.

By default, Nginx sets the keepalive timeout to 75 seconds. However, depending on your specific requirements and server resources, you may need to adjust this value.

To optimize keepalive timeout, follow these steps:

  1. Open your Nginx configuration file using a text editor. The file is typically located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf.
  2. Locate the http block in the configuration file.
  3. Add or modify the keepalive_timeout directive within the http block. For example, to set the keepalive timeout to 60 seconds, use the following line of code:
    keepalive_timeout 60s;
  4. Save the configuration file and exit the text editor.
  5. Restart Nginx to apply the changes. The command to restart Nginx may vary depending on your operating system, but it is typically sudo service nginx restart or sudo systemctl restart nginx.

By adjusting the keepalive timeout value, you can fine-tune the performance of your website based on your specific needs.

Summary

Optimizing keepalive timeout is a crucial step in improving the performance and scalability of your website. By keeping connections open for an optimal duration using the keepalive_timeout directive in Nginx, you can reduce latency, improve resource efficiency, and enhance the overall user experience.

For reliable and high-performance VPS hosting solutions, consider Server.HK. With our top-notch VPS hosting services, you can ensure the optimal performance of your website.

Recent Posts

  • CentOS Stream Explained: Key Differences from CentOS Linux
  • How to Configure FirewallD in CentOS Stream: From Essential to Production-Grade
  • Installing Docker on CentOS: A Practical Setup Guide (CentOS Stream 9/10 – 2026)
  • How to Secure a CentOS Server: 15 Essential Hardening Techniques (CentOS Stream 9/10 – 2026)
  • CentOS End of Life (EOL): What It Means and Migration Options in 2026

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