• 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 sendfile and tcp_nopush for static file delivery

December 19, 2023

Nginx Tip – Optimize sendfile and tcp_nopush for static file delivery

When it comes to delivering static files efficiently, Nginx is a popular choice among web servers. With its high-performance architecture and lightweight design, Nginx can handle a large number of concurrent connections while consuming minimal system resources. In this article, we will explore two important Nginx directives – sendfile and tcp_nopush – that can significantly optimize static file delivery.

The sendfile Directive

The sendfile directive in Nginx allows for direct file transmission from disk to network socket without involving the user-space buffer. This feature improves performance by reducing the number of data copies and system calls required for file delivery.

To enable sendfile in Nginx, you need to add the following line to your Nginx configuration file:

sendfile on;

By default, sendfile is set to “off” in Nginx. Enabling it can provide a significant performance boost, especially when serving large files.

However, there are a few considerations to keep in mind when using sendfile:

  • Sendfile is only supported on Unix-like systems, such as Linux and BSD. It is not available on Windows.
  • Sendfile may not work correctly with some network file systems or virtual file systems.
  • If you are using Nginx with PHP-FPM, you need to disable sendfile in PHP-FPM configuration to avoid potential conflicts.

The tcp_nopush Directive

The tcp_nopush directive in Nginx controls the buffering behavior for sending TCP packets. When tcp_nopush is enabled, Nginx will attempt to send the response headers and the first part of the file in a single packet, reducing the number of packets required for file delivery.

To enable tcp_nopush in Nginx, add the following line to your Nginx configuration file:

tcp_nopush on;

By default, tcp_nopush is set to “off” in Nginx. Enabling it can improve the efficiency of static file delivery, especially for small files.

However, there are a few considerations to keep in mind when using tcp_nopush:

  • Enabling tcp_nopush may increase the latency for delivering the first byte of the response, as Nginx waits for more data to fill the packet before sending it.
  • Some older browsers or proxy servers may not support the TCP_NOPUSH option, resulting in suboptimal performance.

Conclusion

Optimizing static file delivery is crucial for improving website performance and user experience. By enabling the sendfile and tcp_nopush directives in Nginx, you can significantly enhance the efficiency of file transmission. However, it is important to consider the limitations and potential conflicts associated with these directives.

At Server.HK, we offer high-performance VPS hosting solutions that are optimized for Nginx and other web servers. With our reliable and scalable infrastructure, you can ensure fast and efficient delivery of your static files. Learn more about our Hong Kong VPS Hosting services and how we can help you achieve optimal website performance.

Recent Posts

  • How to Set Up Nginx on CentOS Stream for High-Performance Web Hosting
  • 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)

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