{"id":49742,"date":"2024-10-08T07:07:14","date_gmt":"2024-10-07T23:07:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/49742\/"},"modified":"2024-10-08T07:07:14","modified_gmt":"2024-10-07T23:07:14","slug":"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%af%a6%e7%8f%be-ngx_http_slice_module-%e9%80%b2%e8%a1%8c%e5%ad%97%e7%af%80%e7%af%84%e5%9c%8d%e5%bf%ab%e5%8f%96","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/49742\/","title":{"rendered":"Nginx \u6280\u5de7\uff1a\u5be6\u73fe ngx_http_slice_module \u9032\u884c\u5b57\u7bc0\u7bc4\u570d\u5feb\u53d6"},"content":{"rendered":"<h1 id=\"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%af%a6%e7%8f%be-ngx_http_slice_module-%e9%80%b2%e8%a1%8c%e5%ad%97%e7%af%80%e7%af%84%e5%9c%8d%e5%bf%ab%e5%8f%96-cbCiPYxotM\">Nginx \u6280\u5de7\uff1a\u5be6\u73fe ngx_http_slice_module \u9032\u884c\u5b57\u7bc0\u7bc4\u570d\u5feb\u53d6<\/h1>\n<p>Nginx \u662f\u4e00\u6b3e\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u975c\u614b\u548c\u52d5\u614b\u5167\u5bb9\u7684\u63d0\u4f9b\u3002\u96a8\u8457\u7db2\u8def\u6d41\u91cf\u7684\u589e\u52a0\uff0c\u5982\u4f55\u6709\u6548\u5730\u7ba1\u7406\u548c\u5feb\u53d6\u5167\u5bb9\u6210\u70ba\u4e86\u8a31\u591a\u7db2\u7ad9\u7ba1\u7406\u8005\u7684\u91cd\u8981\u8ab2\u984c\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5229\u7528 Nginx \u7684 <code>ngx_http_slice_module<\/code> \u4f86\u5be6\u73fe\u5b57\u7bc0\u7bc4\u570d\u5feb\u53d6\uff0c\u5f9e\u800c\u63d0\u5347\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%ad%97%e7%af%80%e7%af%84%e5%9c%8d%e8%ab%8b%e6%b1%82%ef%bc%9f-cbCiPYxotM\">\u4ec0\u9ebc\u662f\u5b57\u7bc0\u7bc4\u570d\u8acb\u6c42\uff1f<\/h2>\n<p>\u5b57\u7bc0\u7bc4\u570d\u8acb\u6c42\u662f\u4e00\u7a2e HTTP \u8acb\u6c42\uff0c\u5141\u8a31\u5ba2\u6236\u7aef\u8acb\u6c42\u8cc7\u6e90\u7684\u7279\u5b9a\u90e8\u5206\uff0c\u800c\u4e0d\u662f\u6574\u500b\u6587\u4ef6\u3002\u9019\u5728\u8655\u7406\u5927\u578b\u6587\u4ef6\uff08\u5982\u8996\u983b\u6216\u97f3\u983b\uff09\u6642\u7279\u5225\u6709\u7528\uff0c\u56e0\u70ba\u7528\u6236\u53ef\u4ee5\u9078\u64c7\u5f9e\u7279\u5b9a\u4f4d\u7f6e\u958b\u59cb\u64ad\u653e\uff0c\u800c\u4e0d\u5fc5\u7b49\u5f85\u6574\u500b\u6587\u4ef6\u4e0b\u8f09\u5b8c\u6210\u3002<\/p>\n<h2 id=\"ngx_http_slice_module-%e7%9a%84%e5%8a%9f%e8%83%bd-cbCiPYxotM\">ngx_http_slice_module \u7684\u529f\u80fd<\/h2>\n<p><code>ngx_http_slice_module<\/code> \u662f Nginx \u7684\u4e00\u500b\u6a21\u7d44\uff0c\u5c08\u9580\u7528\u65bc\u8655\u7406\u5b57\u7bc0\u7bc4\u570d\u8acb\u6c42\u3002\u5b83\u80fd\u5920\u5c07\u5927\u6587\u4ef6\u5206\u5272\u6210\u591a\u500b\u5c0f\u7247\u6bb5\uff0c\u4e26\u6839\u64da\u5ba2\u6236\u7aef\u7684\u8acb\u6c42\u52d5\u614b\u63d0\u4f9b\u9019\u4e9b\u7247\u6bb5\u3002\u9019\u4e0d\u50c5\u80fd\u6e1b\u5c11\u4f3a\u670d\u5668\u7684\u8ca0\u64d4\uff0c\u9084\u80fd\u63d0\u9ad8\u7528\u6236\u7684\u8a2a\u554f\u901f\u5ea6\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%95%9f%e7%94%a8-ngx_http_slice_module-cbCiPYxotM\">\u5982\u4f55\u555f\u7528 ngx_http_slice_module<\/h2>\n<p>\u8981\u4f7f\u7528 <code>ngx_http_slice_module<\/code>\uff0c\u9996\u5148\u9700\u8981\u78ba\u4fdd Nginx \u5df2\u7d93\u7de8\u8b6f\u4e86\u8a72\u6a21\u7d44\u3002\u5927\u591a\u6578\u73fe\u4ee3\u7684 Nginx \u767c\u884c\u7248\u90fd\u5df2\u7d93\u5305\u542b\u4e86\u9019\u500b\u6a21\u7d44\u3002\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5728 Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u9032\u884c\u76f8\u61c9\u7684\u8a2d\u7f6e\u3002<\/p>\n<h3 id=\"%e9%85%8d%e7%bd%ae%e7%a4%ba%e4%be%8b-cbCiPYxotM\">\u914d\u7f6e\u793a\u4f8b<\/h3>\n<pre><code>http {\n    ...\n    slice 1m;  # \u8a2d\u5b9a\u6bcf\u500b\u7247\u6bb5\u7684\u5927\u5c0f\n    slice_range 1;  # \u555f\u7528\u5b57\u7bc0\u7bc4\u570d\u8acb\u6c42\n\n    server {\n        listen 80;\n        server_name example.com;\n\n        location \/video\/ {\n            # \u6307\u5b9a\u8981\u5feb\u53d6\u7684\u6587\u4ef6\u985e\u578b\n            types {\n                video\/mp4 mp4;\n                video\/x-flv flv;\n            }\n\n            # \u555f\u7528 slice \u6a21\u7d44\n            slice 1m;\n            slice_range 1;\n\n            # \u8a2d\u5b9a\u5feb\u53d6\n            proxy_pass http:\/\/backend;\n            proxy_cache my_cache;\n        }\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u914d\u7f6e\u4e2d\uff0c\u6211\u5011\u5c07\u6bcf\u500b\u7247\u6bb5\u7684\u5927\u5c0f\u8a2d\u7f6e\u70ba 1MB\uff0c\u4e26\u555f\u7528\u4e86\u5b57\u7bc0\u7bc4\u570d\u8acb\u6c42\u3002\u9019\u6a23\uff0c\u7576\u7528\u6236\u8acb\u6c42\u8996\u983b\u6587\u4ef6\u6642\uff0cNginx \u5c07\u6839\u64da\u8acb\u6c42\u7684\u7bc4\u570d\u52d5\u614b\u63d0\u4f9b\u76f8\u61c9\u7684\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e5%84%aa%e5%8c%96-nginx-%e7%9a%84%e6%80%a7%e8%83%bd-cbCiPYxotM\">\u512a\u5316 Nginx \u7684\u6027\u80fd<\/h2>\n<p>\u9664\u4e86\u4f7f\u7528 <code>ngx_http_slice_module<\/code>\uff0c\u9084\u53ef\u4ee5\u901a\u904e\u5176\u4ed6\u65b9\u5f0f\u4f86\u512a\u5316 Nginx \u7684\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u555f\u7528\u5feb\u53d6\u53ef\u4ee5\u986f\u8457\u6e1b\u5c11\u4f3a\u670d\u5668\u7684\u8ca0\u64d4\uff0c\u4e26\u63d0\u9ad8\u97ff\u61c9\u901f\u5ea6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8b70\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 <code>proxy_cache<\/code> \u4f86\u5feb\u53d6\u5f8c\u7aef\u4f3a\u670d\u5668\u7684\u97ff\u61c9\u3002<\/li>\n<li>\u8abf\u6574 <code>worker_processes<\/code> \u548c <code>worker_connections<\/code> \u7684\u6578\u91cf\uff0c\u4ee5\u5145\u5206\u5229\u7528\u4f3a\u670d\u5668\u8cc7\u6e90\u3002<\/li>\n<li>\u555f\u7528 Gzip \u58d3\u7e2e\uff0c\u4ee5\u6e1b\u5c11\u50b3\u8f38\u7684\u6578\u64da\u91cf\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-cbCiPYxotM\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4f7f\u7528 Nginx \u7684 <code>ngx_http_slice_module<\/code>\uff0c\u7db2\u7ad9\u7ba1\u7406\u8005\u53ef\u4ee5\u6709\u6548\u5730\u5be6\u73fe\u5b57\u7bc0\u7bc4\u570d\u5feb\u53d6\uff0c\u5f9e\u800c\u63d0\u5347\u7528\u6236\u7684\u8a2a\u554f\u9ad4\u9a57\u3002\u9019\u4e0d\u50c5\u80fd\u6e1b\u5c11\u4f3a\u670d\u5668\u7684\u8ca0\u64d4\uff0c\u9084\u80fd\u63d0\u9ad8\u7db2\u7ad9\u7684\u6574\u9ad4\u6027\u80fd\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/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\u5167\u5bb9\u9084\u662f\u52d5\u614b\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u5e6b\u52a9\u60a8\u63d0\u5347\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 Nginx \u6280\u5de7\uff0c\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528 ngx_http_slice_module \u5be6\u73fe\u5b57\u7bc0\u7bc4\u570d\u5feb\u53d6\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u7528\u6236\u9ad4\u9a57\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-49742","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49742","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=49742"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49742\/revisions"}],"predecessor-version":[{"id":49743,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49742\/revisions\/49743"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=49742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=49742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=49742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}