{"id":18066,"date":"2024-11-18T17:27:23","date_gmt":"2024-11-18T09:27:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18066\/"},"modified":"2024-11-18T17:27:23","modified_gmt":"2024-11-18T09:27:23","slug":"nginx%e6%80%8e%e4%b9%88%e5%90%af%e7%94%a8stream","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18066\/","title":{"rendered":"nginx\u600e\u4e48\u542f\u7528stream"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u542f\u7528 nginx \u7684 stream \u6a21\u5757\uff1f\u542f\u7528 stream \u6a21\u5757\u9700\u8981\u516d\u4e2a\u6b65\u9aa4\uff1a\u5b89\u88c5 stream \u6a21\u5757\u914d\u7f6e nginx\u521b\u5efa stream \u670d\u52a1\u5668\u5757\u914d\u7f6e stream \u670d\u52a1\u5668\u9009\u9879\u91cd\u542f nginx\u9a8c\u8bc1\u542f\u7528\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/27\/2024052721392361552.jpg\" class=\"aligncenter\" title=\"nginx\u600e\u4e48\u542f\u7528stream\u63d2\u56fe\" alt=\"nginx\u600e\u4e48\u542f\u7528stream\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u542f\u7528 Nginx \u7684 Stream \u6a21\u5757<\/strong><\/p>\n<p>\u542f\u7528 Nginx \u7684 Stream \u6a21\u5757\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u5b89\u88c5 Stream \u6a21\u5757<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u60a8\u5df2\u5b89\u88c5\u4e86 Nginx Stream \u6a21\u5757\u3002\u5728\u5927\u591a\u6570 Linux \u53d1\u884c\u7248\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<pre>sudo apt install nginx-stream-module<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6216\uff1a<\/p>\n<pre>sudo yum install nginx-stream-module<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u914d\u7f6e Nginx<\/strong><\/p>\n<p>\u5b89\u88c5\u6a21\u5757\u540e\uff0c\u60a8\u9700\u8981\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u52a0\u8f7d\u5b83\u3002\u6253\u5f00 Nginx \u914d\u7f6e\u6587\u4ef6 (\/etc\/\/nginx.conf)\uff0c\u5e76\u5728 http \u5757\u4e4b\u5916\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>load_module modules\/ngx_stream_module.so;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u521b\u5efa Stream \u670d\u52a1\u5668\u5757<\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u60a8\u9700\u8981\u521b\u5efa\u4e00\u4e2a Stream \u670d\u52a1\u5668\u5757\u6765\u5b9a\u4e49\u5c06\u4f7f\u7528 Stream \u6a21\u5757\u7684\u670d\u52a1\u5668\u7684\u914d\u7f6e\u3002\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\uff1a<\/p>\n<pre>stream {\n    server {\n        listen 8080;\n\n        # \u8fd9\u91cc\u914d\u7f6e Stream \u670d\u52a1\u5668\u7684\u9009\u9879...\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u914d\u7f6e Stream \u670d\u52a1\u5668\u9009\u9879<\/strong><\/p>\n<p>\u5728\u8fd9\u4e2a Stream \u670d\u52a1\u5668\u5757\u4e2d\uff0c\u60a8\u53ef\u4ee5\u914d\u7f6e\u5404\u79cd\u9009\u9879\u6765\u63a7\u5236\u670d\u52a1\u5668\u7684\u884c\u4e3a\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u6307\u5b9a\u8981\u76d1\u542c\u7684\u7aef\u53e3\uff08\u5728\u672c\u4f8b\u4e2d\u4e3a 8080\uff09\uff0c\u4ee5\u53ca\u8981\u4f7f\u7528\u7684\u534f\u8bae\uff08\u5982 TCP\u3001UDP \u6216 TLS\uff09\u3002<\/p>\n<p><strong>5. \u91cd\u542f Nginx<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u91cd\u65b0\u542f\u52a8 Nginx \u4ee5\u5e94\u7528\u66f4\u6539\uff1a<\/p>\n<pre>sudo systemctl restart nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u9a8c\u8bc1\u542f\u7528<\/strong><\/p>\n<p>\u73b0\u5728\uff0cStream \u6a21\u5757\u5df2\u542f\u7528\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5 Nginx \u8fdb\u7a0b\u5217\u8868\u6765\u9a8c\u8bc1\uff1a<\/p>\n<pre>sudo systemctl status nginx | grep -i stream<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u8f93\u51fa\u4e2d\u663e\u793a &#8220;ngx_stream_module (stream)&#8221;, \u5219\u8868\u660e Stream \u6a21\u5757\u5df2\u6210\u529f\u542f\u7528\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u542f\u7528stream\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u542f\u7528 nginx \u7684 stream \u6a21\u5757\uff1f\u542f\u7528 stream \u6a21\u5757\u9700\u8981\u516d\u4e2a\u6b65\u9aa4\uff1a\u5b89\u88c5 stream \u6a21\u5757\u914d\u7f6e nginx\u521b\u5efa stream \u670d\u52a1\u5668\u5757\u914d\u7f6e stream \u670d\u52a1\u5668\u9009\u9879\u91cd\u542f nginx\u9a8c\u8bc1\u542f\u7528 \u5982\u4f55\u542f\u7528 Nginx \u7684 Stream \u6a21\u5757 \u542f\u7528 Nginx \u7684 Stream \u6a21\u5757\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u5b89\u88c5 Stream \u6a21\u5757 \u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u60a8\u5df2\u5b89\u88c5\u4e86 Nginx Stream \u6a21\u5757\u3002\u5728\u5927\u591a\u6570 Linux \u53d1\u884c\u7248\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a sudo apt install nginx-stream-module \u767b\u5f55\u540e\u590d\u5236 \u6216\uff1a sudo yum install nginx-stream-module \u767b\u5f55\u540e\u590d\u5236 2. \u914d\u7f6e Nginx \u5b89\u88c5\u6a21\u5757\u540e\uff0c\u60a8\u9700\u8981\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u52a0\u8f7d\u5b83\u3002\u6253\u5f00 Nginx \u914d\u7f6e\u6587\u4ef6 (\/etc\/\/nginx.conf)\uff0c\u5e76\u5728 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-18066","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18066"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18066\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}