{"id":49878,"date":"2024-10-08T08:15:13","date_gmt":"2024-10-08T00:15:13","guid":{"rendered":"https:\/\/server.hk\/cnblog\/49878\/"},"modified":"2024-10-08T08:15:14","modified_gmt":"2024-10-08T00:15:14","slug":"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%84%aa%e5%8c%96-sendfile-%e5%92%8c-tcp_nopush-%e9%80%b2%e8%a1%8c%e9%9d%9c%e6%85%8b%e6%96%87%e4%bb%b6%e4%ba%a4%e4%bb%98","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/49878\/","title":{"rendered":"Nginx \u6280\u5de7\uff1a\u512a\u5316 sendfile \u548c tcp_nopush \u9032\u884c\u975c\u614b\u6587\u4ef6\u4ea4\u4ed8"},"content":{"rendered":"<h1 id=\"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%84%aa%e5%8c%96-sendfile-%e5%92%8c-tcp_nopush-%e9%80%b2%e8%a1%8c%e9%9d%9c%e6%85%8b%e6%96%87%e4%bb%b6%e4%ba%a4%e4%bb%98-umyiCCBTky\">Nginx \u6280\u5de7\uff1a\u512a\u5316 sendfile \u548c tcp_nopush \u9032\u884c\u975c\u614b\u6587\u4ef6\u4ea4\u4ed8<\/h1>\n<p>Nginx \u662f\u4e00\u6b3e\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u975c\u614b\u6587\u4ef6\u7684\u4ea4\u4ed8\u3002\u70ba\u4e86\u9032\u4e00\u6b65\u63d0\u5347\u975c\u614b\u6587\u4ef6\u7684\u50b3\u8f38\u6548\u7387\uff0c\u512a\u5316 Nginx \u7684\u914d\u7f6e\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u901a\u904e\u512a\u5316 <code>sendfile<\/code> \u548c <code>tcp_nopush<\/code> \u4f86\u63d0\u9ad8\u975c\u614b\u6587\u4ef6\u7684\u4ea4\u4ed8\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-sendfile%ef%bc%9f-umyiCCBTky\">\u4ec0\u9ebc\u662f sendfile\uff1f<\/h2>\n<p><code>sendfile<\/code> \u662f\u4e00\u500b\u7cfb\u7d71\u8abf\u7528\uff0c\u5141\u8a31\u4f3a\u670d\u5668\u76f4\u63a5\u5f9e\u6587\u4ef6\u7cfb\u7d71\u5c07\u6578\u64da\u767c\u9001\u5230\u7db2\u7d61\u5957\u63a5\u5b57\uff0c\u800c\u7121\u9700\u5c07\u6578\u64da\u8907\u88fd\u5230\u7528\u6236\u7a7a\u9593\u3002\u9019\u6a23\u53ef\u4ee5\u6e1b\u5c11\u4e0a\u4e0b\u6587\u5207\u63db\u7684\u958b\u92b7\uff0c\u5f9e\u800c\u63d0\u9ad8\u6027\u80fd\u3002\u5728 Nginx \u4e2d\uff0c\u555f\u7528 <code>sendfile<\/code> \u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u975c\u614b\u6587\u4ef6\u7684\u50b3\u8f38\u901f\u5ea6\u3002<\/p>\n<h3 id=\"%e5%a6%82%e4%bd%95%e5%95%9f%e7%94%a8-sendfile-umyiCCBTky\">\u5982\u4f55\u555f\u7528 sendfile<\/h3>\n<p>\u8981\u5728 Nginx \u4e2d\u555f\u7528 <code>sendfile<\/code>\uff0c\u53ea\u9700\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>sendfile on;<\/code><\/pre>\n<p>\u9019\u884c\u4ee3\u78bc\u901a\u5e38\u653e\u5728 <code>http<\/code> \u5340\u584a\u4e2d\u3002\u555f\u7528\u5f8c\uff0cNginx \u5c07\u4f7f\u7528 <code>sendfile<\/code> \u4f86\u8655\u7406\u975c\u614b\u6587\u4ef6\u7684\u8acb\u6c42\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-tcp_nopush%ef%bc%9f-umyiCCBTky\">\u4ec0\u9ebc\u662f tcp_nopush\uff1f<\/h2>\n<p><code>tcp_nopush<\/code> \u662f\u4e00\u500b TCP \u5354\u8b70\u9078\u9805\uff0c\u65e8\u5728\u512a\u5316\u6578\u64da\u5305\u7684\u767c\u9001\u3002\u7576\u8a2d\u7f6e\u70ba <code>on<\/code> \u6642\uff0cNginx \u5c07\u5728\u767c\u9001\u6578\u64da\u6642\uff0c\u7b49\u5f85\u76f4\u5230\u6240\u6709\u6578\u64da\u90fd\u6e96\u5099\u597d\uff0c\u7136\u5f8c\u4e00\u6b21\u6027\u767c\u9001\uff0c\u9019\u6a23\u53ef\u4ee5\u6e1b\u5c11 TCP \u6578\u64da\u5305\u7684\u6578\u91cf\uff0c\u5f9e\u800c\u63d0\u9ad8\u50b3\u8f38\u6548\u7387\u3002<\/p>\n<h3 id=\"%e5%a6%82%e4%bd%95%e5%95%9f%e7%94%a8-tcp_nopush-umyiCCBTky\">\u5982\u4f55\u555f\u7528 tcp_nopush<\/h3>\n<p>\u5728 Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u65b9\u5f0f\u555f\u7528 <code>tcp_nopush<\/code>\uff1a<\/p>\n<pre><code>tcp_nopush on;<\/code><\/pre>\n<p>\u9019\u884c\u4ee3\u78bc\u540c\u6a23\u61c9\u653e\u5728 <code>http<\/code> \u5340\u584a\u4e2d\u3002\u555f\u7528\u5f8c\uff0cNginx \u5c07\u5728\u767c\u9001\u5927\u6587\u4ef6\u6642\u4f7f\u7528\u6b64\u9078\u9805\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<h2 id=\"sendfile-%e5%92%8c-tcp_nopush-%e7%9a%84%e7%b5%90%e5%90%88%e4%bd%bf%e7%94%a8-umyiCCBTky\">sendfile \u548c tcp_nopush \u7684\u7d50\u5408\u4f7f\u7528<\/h2>\n<p>\u5c07 <code>sendfile<\/code> \u548c <code>tcp_nopush<\/code> \u7d50\u5408\u4f7f\u7528\uff0c\u53ef\u4ee5\u9032\u4e00\u6b65\u63d0\u5347\u975c\u614b\u6587\u4ef6\u7684\u4ea4\u4ed8\u6027\u80fd\u3002\u7576 <code>sendfile<\/code> \u88ab\u555f\u7528\u6642\uff0cNginx \u5c07\u76f4\u63a5\u5f9e\u78c1\u789f\u767c\u9001\u6578\u64da\uff0c\u800c <code>tcp_nopush<\/code> \u5247\u78ba\u4fdd\u6578\u64da\u4ee5\u6700\u512a\u7684\u65b9\u5f0f\u767c\u9001\u3002<\/p>\n<h3 id=\"%e9%85%8d%e7%bd%ae%e7%a4%ba%e4%be%8b-umyiCCBTky\">\u914d\u7f6e\u793a\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684 Nginx \u914d\u7f6e\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u540c\u6642\u555f\u7528 <code>sendfile<\/code> \u548c <code>tcp_nopush<\/code>\uff1a<\/p>\n<pre><code>http {\n    sendfile on;\n    tcp_nopush on;\n\n    server {\n        listen 80;\n        server_name example.com;\n\n        location \/ {\n            root \/path\/to\/static\/files;\n            index index.html;\n        }\n    }\n}<\/code><\/pre>\n<p>\u5728\u9019\u500b\u914d\u7f6e\u4e2d\uff0cNginx \u5c07\u70ba <code>example.com<\/code> \u63d0\u4f9b\u975c\u614b\u6587\u4ef6\u670d\u52d9\uff0c\u4e26\u5229\u7528 <code>sendfile<\/code> \u548c <code>tcp_nopush<\/code> \u4f86\u512a\u5316\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e6%80%a7%e8%83%bd%e6%b8%ac%e8%a9%a6-umyiCCBTky\">\u6027\u80fd\u6e2c\u8a66<\/h2>\n<p>\u5728\u555f\u7528\u9019\u4e9b\u9078\u9805\u5f8c\uff0c\u5efa\u8b70\u9032\u884c\u6027\u80fd\u6e2c\u8a66\uff0c\u4ee5\u78ba\u4fdd\u914d\u7f6e\u7684\u6709\u6548\u6027\u3002\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5982 <code>ab<\/code>\uff08Apache Benchmark\uff09\u6216 <code>wrk<\/code> \u4f86\u6e2c\u8a66\u975c\u614b\u6587\u4ef6\u7684\u97ff\u61c9\u6642\u9593\u548c\u541e\u5410\u91cf\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-umyiCCBTky\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u512a\u5316 Nginx \u7684 <code>sendfile<\/code> \u548c <code>tcp_nopush<\/code> \u8a2d\u7f6e\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u975c\u614b\u6587\u4ef6\u7684\u4ea4\u4ed8\u6027\u80fd\u3002\u9019\u4e9b\u914d\u7f6e\u4e0d\u50c5\u80fd\u6e1b\u5c11\u4f3a\u670d\u5668\u7684\u8ca0\u64d4\uff0c\u9084\u80fd\u63d0\u5347\u7528\u6236\u7684\u8a2a\u554f\u9ad4\u9a57\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u975c\u614b\u6587\u4ef6\u4ea4\u4ed8\u7684\u7db2\u7ad9\uff0c\u9019\u4e9b\u6280\u5de7\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u7121\u8ad6\u662f\u975c\u614b\u7db2\u7ad9\u9084\u662f\u52d5\u614b\u61c9\u7528\uff0c\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 Nginx \u6280\u5de7\uff0c\u512a\u5316 sendfile \u548c tcp_nopush \u8a2d\u7f6e\uff0c\u63d0\u5347\u975c\u614b\u6587\u4ef6\u4ea4\u4ed8\u6548\u7387\uff0c\u589e\u5f37\u7db2\u7ad9\u6027\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-49878","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49878","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=49878"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49878\/revisions"}],"predecessor-version":[{"id":49879,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49878\/revisions\/49879"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=49878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=49878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=49878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}