{"id":50785,"date":"2024-10-08T13:42:45","date_gmt":"2024-10-08T05:42:45","guid":{"rendered":"https:\/\/server.hk\/cnblog\/50785\/"},"modified":"2024-10-08T13:42:45","modified_gmt":"2024-10-08T05:42:45","slug":"nginx-%e6%8c%87%e4%bb%a4%ef%bc%9asendfile-%ef%bc%88%e7%99%bc%e9%80%81%e6%96%87%e4%bb%b6%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/50785\/","title":{"rendered":"Nginx \u6307\u4ee4\uff1asendfile \uff08\u767c\u9001\u6587\u4ef6\uff09"},"content":{"rendered":"<h1 id=\"nginx-%e6%8c%87%e4%bb%a4%ef%bc%9asendfile-%ef%bc%88%e7%99%bc%e9%80%81%e6%96%87%e4%bb%b6%ef%bc%89-PeZfiHotWa\">Nginx \u6307\u4ee4\uff1asendfile \uff08\u767c\u9001\u6587\u4ef6\uff09<\/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\u50b3\u8f38\u3002\u5176\u5167\u5efa\u7684\u6307\u4ee4\u4e4b\u4e00\uff0c<code>sendfile<\/code>\uff0c\u5c08\u9580\u7528\u65bc\u512a\u5316\u6587\u4ef6\u7684\u50b3\u9001\u904e\u7a0b\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e <code>sendfile<\/code> \u6307\u4ee4\u7684\u529f\u80fd\u3001\u4f7f\u7528\u65b9\u6cd5\u53ca\u5176\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u7684\u512a\u52e2\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-sendfile-%e6%8c%87%e4%bb%a4%ef%bc%9f-PeZfiHotWa\">\u4ec0\u9ebc\u662f sendfile \u6307\u4ee4\uff1f<\/h2>\n<p><code>sendfile<\/code> \u662f Nginx \u4e2d\u7684\u4e00\u500b\u6307\u4ee4\uff0c\u4e3b\u8981\u7528\u65bc\u5c07\u6587\u4ef6\u76f4\u63a5\u5f9e\u78c1\u789f\u50b3\u9001\u5230\u7db2\u8def\u9023\u63a5\uff0c\u800c\u4e0d\u9700\u8981\u7d93\u904e\u7528\u6236\u7a7a\u9593\u7684\u7de9\u885d\u5340\u3002\u9019\u6a23\u7684\u8a2d\u8a08\u53ef\u4ee5\u6e1b\u5c11\u4e0a\u4e0b\u6587\u5207\u63db\u7684\u958b\u92b7\uff0c\u5f9e\u800c\u63d0\u9ad8\u6587\u4ef6\u50b3\u8f38\u7684\u6548\u7387\u3002<\/p>\n<h2 id=\"sendfile-%e7%9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86-PeZfiHotWa\">sendfile \u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<p>\u7576\u5ba2\u6236\u7aef\u8acb\u6c42\u4e00\u500b\u975c\u614b\u6587\u4ef6\u6642\uff0cNginx \u6703\u4f7f\u7528 <code>sendfile<\/code> \u6307\u4ee4\u5c07\u8a72\u6587\u4ef6\u76f4\u63a5\u5f9e\u78c1\u789f\u8b80\u53d6\u4e26\u767c\u9001\u5230\u5ba2\u6236\u7aef\u3002\u9019\u4e00\u904e\u7a0b\u4e2d\uff0cNginx \u6703\u5229\u7528\u64cd\u4f5c\u7cfb\u7d71\u7684\u5167\u5efa\u529f\u80fd\uff0c\u5c07\u6587\u4ef6\u7684\u5167\u5bb9\u76f4\u63a5\u5f9e\u78c1\u789f\u50b3\u9001\u5230\u7db2\u8def\u5957\u63a5\u5b57\uff0c\u907f\u514d\u4e86\u4e0d\u5fc5\u8981\u7684\u6578\u64da\u8907\u88fd\u3002<\/p>\n<h3 id=\"sendfile-%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%aa%9e%e6%b3%95-PeZfiHotWa\">sendfile \u7684\u57fa\u672c\u8a9e\u6cd5<\/h3>\n<pre><code>sendfile on|off;<\/code><\/pre>\n<p>\u5728 Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8a9e\u6cd5\u4f86\u555f\u7528\u6216\u7981\u7528 <code>sendfile<\/code> \u6307\u4ee4\uff1a<\/p>\n<h4 id=\"%e7%af%84%e4%be%8b%e9%85%8d%e7%bd%ae-PeZfiHotWa\">\u7bc4\u4f8b\u914d\u7f6e<\/h4>\n<pre><code>http {\n    sendfile on;\n    ...\n}<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c<code>sendfile<\/code> \u88ab\u8a2d\u7f6e\u70ba\u958b\u555f\uff0c\u9019\u610f\u5473\u8457 Nginx \u5c07\u6703\u4f7f\u7528\u9019\u500b\u6307\u4ee4\u4f86\u8655\u7406\u975c\u614b\u6587\u4ef6\u7684\u50b3\u8f38\u3002<\/p>\n<h2 id=\"sendfile-%e7%9a%84%e5%84%aa%e5%8b%a2-PeZfiHotWa\">sendfile \u7684\u512a\u52e2<\/h2>\n<ul>\n<li><strong>\u63d0\u9ad8\u6027\u80fd\uff1a<\/strong>\u7531\u65bc <code>sendfile<\/code> \u76f4\u63a5\u5728\u5167\u6838\u7a7a\u9593\u4e2d\u8655\u7406\u6587\u4ef6\u50b3\u8f38\uff0c\u9019\u6a23\u53ef\u4ee5\u986f\u8457\u6e1b\u5c11 CPU \u7684\u8ca0\u64d4\uff0c\u63d0\u5347\u6574\u9ad4\u6027\u80fd\u3002<\/li>\n<li><strong>\u6e1b\u5c11\u5ef6\u9072\uff1a<\/strong>\u901a\u904e\u6e1b\u5c11\u4e0a\u4e0b\u6587\u5207\u63db\uff0c<code>sendfile<\/code> \u53ef\u4ee5\u964d\u4f4e\u6587\u4ef6\u50b3\u8f38\u7684\u5ef6\u9072\uff0c\u7279\u5225\u662f\u5728\u9ad8\u6d41\u91cf\u7684\u60c5\u6cc1\u4e0b\u3002<\/li>\n<li><strong>\u7c21\u5316\u4ee3\u78bc\uff1a<\/strong>\u4f7f\u7528 <code>sendfile<\/code> \u53ef\u4ee5\u7c21\u5316\u61c9\u7528\u7a0b\u5f0f\u7684\u4ee3\u78bc\uff0c\u56e0\u70ba\u4e0d\u9700\u8981\u624b\u52d5\u7ba1\u7406\u7de9\u885d\u5340\u3002<\/li>\n<\/ul>\n<h2 id=\"%e4%bd%bf%e7%94%a8-sendfile-%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-PeZfiHotWa\">\u4f7f\u7528 sendfile \u7684\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5118\u7ba1 <code>sendfile<\/code> \u6709\u8a31\u591a\u512a\u52e2\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u4f7f\u7528\u5b83\u53ef\u80fd\u6703\u5c0e\u81f4\u554f\u984c\u3002\u4f8b\u5982\uff0c\u7576\u6587\u4ef6\u7684\u5927\u5c0f\u8d85\u904e\u4e86\u7cfb\u7d71\u7684\u7de9\u885d\u5340\u5927\u5c0f\u6642\uff0c\u53ef\u80fd\u6703\u51fa\u73fe\u6027\u80fd\u4e0b\u964d\u7684\u60c5\u6cc1\u3002\u6b64\u5916\uff0c\u67d0\u4e9b\u7db2\u8def\u5354\u8b70\uff08\u5982 HTTP\/1.1\uff09\u5728\u4f7f\u7528 <code>sendfile<\/code> \u6642\u53ef\u80fd\u6703\u9047\u5230\u554f\u984c\uff0c\u56e0\u6b64\u5728\u914d\u7f6e\u6642\u9700\u8981\u8b39\u614e\u8003\u616e\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-PeZfiHotWa\">\u7d50\u8ad6<\/h2>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0c<code>sendfile<\/code> \u662f Nginx \u4e2d\u4e00\u500b\u5f37\u5927\u7684\u6307\u4ee4\uff0c\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u975c\u614b\u6587\u4ef6\u7684\u50b3\u8f38\u6548\u7387\u3002\u901a\u904e\u5408\u7406\u914d\u7f6e <code>sendfile<\/code>\uff0c\u53ef\u4ee5\u5728\u9ad8\u6d41\u91cf\u7684\u74b0\u5883\u4e2d\u7372\u5f97\u66f4\u597d\u7684\u6027\u80fd\u8868\u73fe\u3002\u5c0d\u65bc\u9700\u8981\u8655\u7406\u5927\u91cf\u975c\u614b\u5167\u5bb9\u7684\u7db2\u7ad9\u4f86\u8aaa\uff0c\u9019\u662f\u4e00\u500b\u4e0d\u53ef\u6216\u7f3a\u7684\u529f\u80fd\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u80fd\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\u5ba2\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>\u4e86\u89e3 Nginx \u7684 sendfile \u6307\u4ee4\uff0c\u63d0\u5347\u6587\u4ef6\u50b3\u8f38\u6548\u7387\uff0c\u6e1b\u5c11 CPU \u4f7f\u7528\uff0c\u5be6\u73fe\u9ad8\u6548\u80fd\u7684\u975c\u614b\u6587\u4ef6\u670d\u52d9\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-50785","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50785","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=50785"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50785\/revisions"}],"predecessor-version":[{"id":50786,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50785\/revisions\/50786"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=50785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=50785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=50785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}