{"id":30479,"date":"2025-04-20T20:41:05","date_gmt":"2025-04-20T12:41:05","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/30479.html"},"modified":"2025-04-20T20:41:05","modified_gmt":"2025-04-20T12:41:05","slug":"%e3%80%90%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9f%a5%e8%af%86%e3%80%91nginx%e6%80%a7%e8%83%bd%e4%b8%8d%e5%a4%9f-%e6%88%91%e4%bb%ac%e8%bf%98%e6%9c%89pingora","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/30479.html","title":{"rendered":"\u3010\u670d\u52a1\u5668\u77e5\u8bc6\u3011nginx\u6027\u80fd\u4e0d\u591f, \u6211\u4eec\u8fd8\u6709pingora"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\n<ul>\n<li>\u6982\u8ff0<\/li>\n<li>\n<ul>\n<li>\u4e00\u3001\u6846\u67b6\u5185\u5bb9<\/li>\n<li>\u4e8c\u3001\u4e3b\u8981\u7279\u6027<\/li>\n<li>\u4e09\u3001\u4e3b\u8981\u7ec4\u4ef6<\/li>\n<li>\u56db\u3001\u5e94\u7528\u573a\u666f<\/li>\n<li>\u4e94\u3001\u4f7f\u7528\u4e0e\u793e\u533a<\/li>\n<\/ul>\n<\/li>\n<li>\u5feb\u901f\u6784\u5efa\u4e00\u4e2a\u8d1f\u8f7d\u5747\u8861\u5668<\/li>\n<li>\n<ul>\n<li>\u6784\u5efa\u57fa\u672c\u8d1f\u8f7d\u5747\u8861\u5668<\/li>\n<li>\u521b\u5efa pingora \u670d\u52a1\u5668<\/li>\n<li>\u521b\u5efa\u8d1f\u8f7d\u5747\u8861\u5668\u4ee3\u7406<\/li>\n<li>\u521b\u5efa pingora-proxy \u670d\u52a1<\/li>\n<\/ul>\n<\/li>\n<li>\u6dfb\u52a0\u529f\u80fd<\/li>\n<li>\n<ul>\n<li>\u540c\u884c\u5065\u5eb7\u68c0\u67e5<\/li>\n<li>\u547d\u4ee4\u884c\u9009\u9879<\/li>\n<li>\u5728\u540e\u53f0\u8fd0\u884c<\/li>\n<li>\u914d\u7f6e<\/li>\n<li>\u4f18\u96c5\u5730\u5347\u7ea7\u670d\u52a1&#xff08;\u4ec5\u9650 Linux&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u6982\u8ff0<\/h3>\n<p>Pingora\u662f\u4e00\u4e2a\u7528Rust\u7f16\u5199\u7684\u8f6f\u4ef6\u5e93&#xff0c;\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u6784\u5efa\u5feb\u901f\u3001\u53ef\u9760\u4e14\u6613\u4e8e\u8fed\u4ee3\u5347\u7ea7\u7684\u7f51\u7edc\u670d\u52a1\u3002\u4ee5\u4e0b\u662f\u5bf9Pingora\u7684\u8be6\u7ec6\u4ecb\u7ecd&#xff1a;<\/p>\n<h4>\u4e00\u3001\u6846\u67b6\u5185\u5bb9<\/h4>\n<p>Pingora \u63d0\u4f9b\u5728 HTTP\/1 \u548c HTTP\/2\u3001 TLS \u6216\u4ec5 TCP \/ UDP \u4e4b\u4e0a\u6784\u5efa\u670d\u52a1\u7684\u5e93\u548c API\u3002\u4f5c\u4e3a\u4ee3\u7406&#xff0c;\u5b83\u652f\u6301 HTTP\/1 \u548c HTTP\/2 \u7aef\u5230\u7aef\u3001gRPC \u548c websocket \u4ee3\u7406\u3002&#xff08;HTTP\/3 \u652f\u6301\u5728\u8def\u7ebf\u56fe\u4e0a&#xff09;\u3002\u5b83\u8fd8\u63d0\u4f9b\u53ef\u81ea\u5b9a\u4e49\u7684\u8d1f\u8f7d\u5e73\u8861\u548c\u6545\u969c\u8f6c\u79fb\u7b56\u7565\u3002\u5728\u5408\u89c4\u6027\u548c\u5b89\u5168\u6027\u65b9\u9762&#xff0c;\u5b83\u540c\u65f6\u652f\u6301\u5e38\u7528\u7684 OpenSSL \u548c BoringSSL \u5e93&#xff0c;\u4e24\u8005\u5747\u7b26\u5408 FIPS \u8981\u6c42\u5e76\u652f\u6301\u540e\u91cf\u5b50\u52a0\u5bc6\u3002<\/p>\n<p>\u9664\u4e86\u63d0\u4f9b\u4ee5\u4e0a\u529f\u80fd&#xff0c;Pingora \u8fd8\u63d0\u4f9b\u8fc7\u6ee4\u5668\u548c\u56de\u8c03\u51fd\u6570&#xff0c;\u8ba9\u7528\u6237\u5b8c\u5168\u81ea\u5b9a\u4e49\u670d\u52a1\u5e94\u8be5\u5982\u4f55\u5904\u7406\u3001\u8f6c\u6362\u548c\u8f6c\u53d1\u8bf7\u6c42\u3002\u8fd9\u4e9b API \u5bf9\u4e8e OpenResty \u548c NGINX \u7528\u6237\u6765\u8bf4\u5e94\u8be5\u5f88\u719f\u6089&#xff0c;\u56e0\u4e3a\u8bb8\u591a API \u76f4\u89c2\u5730\u6620\u5c04\u5230 OpenResty \u7684 \u201c*_by_lua\u201d \u56de\u8c03\u51fd\u6570\u4e0a\u3002<\/p>\n<p>\u5728\u8fd0\u884c\u65b9\u9762&#xff0c;Pingora \u63d0\u4f9b\u96f6\u505c\u673a\u4f18\u96c5\u91cd\u542f&#xff0c;\u4ee5\u4fbf\u5728\u4e0d\u4e22\u5931\u4efb\u4f55\u4f20\u5165\u8bf7\u6c42\u7684\u60c5\u51b5\u4e0b\u8fdb\u884c\u81ea\u8eab\u5347\u7ea7\u3002Syslog\u3001Prometheus\u3001Sentry\u3001OpenTelemetry \u548c\u5176\u4ed6\u5fc5\u5907\u7684\u53ef\u89c2\u5bdf\u6027\u5de5\u5177\u4e5f\u53ef\u4ee5\u8f7b\u677e\u4e0e Pingora \u96c6\u6210\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250420124104-6804eb60cdf42.webp\" alt=\"pingora-req-flow\" \/><\/p>\n<h4>\u4e8c\u3001\u4e3b\u8981\u7279\u6027<\/h4>\n<li>\u9ad8\u6027\u80fd&#xff1a;Pingora\u5145\u5206\u5229\u7528\u4e86\u5f02\u6b65Rust\u7684\u5a01\u529b&#xff0c;\u4fdd\u8bc1\u4e86\u670d\u52a1\u7684\u901f\u5ea6\u548c\u53ef\u9760\u6027\u3002\u5b83\u5728Cloudflare\u7684\u5b9e\u9645\u8fd0\u8425\u4e2d\u7ecf\u53d7\u4e86\u8003\u9a8c&#xff0c;\u6bcf\u5929\u5904\u7406\u8d85\u8fc74\u4ebf\u6b21\u4e92\u8054\u7f51\u8bf7\u6c42&#xff0c;\u5c55\u73b0\u4e86\u5176\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/li>\n<li>\u591a\u534f\u8bae\u652f\u6301&#xff1a;Pingora\u652f\u6301HTTP 1\/2\u7aef\u5230\u7aef\u4ee3\u7406&#xff0c;\u5e76\u80fd\u5904\u7406TLS\u8fde\u63a5&#xff08;\u901a\u8fc7OpenSSL\u6216BoringSSL&#xff09;\u3002\u6b64\u5916&#xff0c;\u8fd8\u63d0\u4f9bgRPC\u548cWebSocket\u7684\u4ee3\u7406\u529f\u80fd\u3002<\/li>\n<li>\u4f18\u96c5\u91cd\u542f\u673a\u5236&#xff1a;Pingora\u63d0\u4f9b\u4e86\u4f18\u96c5\u7684\u91cd\u542f\u673a\u5236&#xff0c;\u4f7f\u5f97\u670d\u52a1\u5728\u5347\u7ea7\u6216\u7ef4\u62a4\u65f6\u80fd\u591f\u65e0\u7f1d\u5207\u6362&#xff0c;\u4e0d\u5f71\u54cd\u7528\u6237\u4f53\u9a8c\u3002<\/li>\n<li>\u5b9a\u5236\u5316\u8d1f\u8f7d\u5747\u8861\u548c\u6545\u969c\u5207\u6362\u7b56\u7565&#xff1a;Pingora\u5141\u8bb8\u5f00\u53d1\u8005\u6839\u636e\u9700\u6c42\u5b9a\u5236\u8d1f\u8f7d\u5747\u8861\u548c\u6545\u969c\u5207\u6362\u7b56\u7565&#xff0c;\u4ee5\u6ee1\u8db3\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u9700\u6c42\u3002<\/li>\n<li>\u9ad8\u5185\u5b58\u5b89\u5168\u6027&#xff1a;\u4e0eC\/C&#043;&#043;\u76f8\u6bd4&#xff0c;Pingora\u4ee5\u66f4\u9ad8\u7684\u5185\u5b58\u5b89\u5168\u6027\u4fdd\u969c\u670d\u52a1\u8fd0\u884c&#xff0c;\u964d\u4f4e\u4e86\u5185\u5b58\u6cc4\u6f0f\u548c\u7f13\u51b2\u533a\u6ea2\u51fa\u7684\u98ce\u9669\u3002<\/li>\n<li>\u9ad8\u53ef\u7f16\u7a0b\u6027&#xff1a;Pingora\u7684\u9ad8\u53ef\u7f16\u7a0b\u6027\u8ba9\u5f00\u53d1\u8005\u53ef\u4ee5\u968f\u5fc3\u6240\u6b32\u5730\u8c03\u6574\u548c\u6269\u5c55&#xff0c;\u4ee5\u6ee1\u8db3\u7279\u5b9a\u9700\u6c42\u3002<\/li>\n<h4>\u4e09\u3001\u4e3b\u8981\u7ec4\u4ef6<\/h4>\n<p>Pingora\u9879\u76ee\u4e0b\u5305\u542b\u4e86\u591a\u4e2a\u72ec\u7acb\u7684crate&#xff0c;\u5982&#xff1a;<\/p>\n<li>pingora&#xff1a;\u6784\u5efa\u7f51\u7edc\u7cfb\u7edf\u548c\u4ee3\u7406\u7684\u4e3b\u8981\u63a5\u53e3\u3002<\/li>\n<li>pingora-core&#xff1a;\u5b9a\u4e49\u534f\u8bae\u3001\u529f\u80fd\u548c\u57fa\u672c\u7279\u6027\u3002<\/li>\n<li>pingora-proxy&#xff1a;HTTP\u4ee3\u7406\u903b\u8f91\u53ca\u76f8\u5173API\u3002<\/li>\n<li>pingora-error&#xff1a;\u5168\u9879\u76ee\u901a\u7528\u7684\u9519\u8bef\u7c7b\u578b\u3002<\/li>\n<li>pingora-http&#xff1a;HTTP\u5934\u5b9a\u4e49\u53caAPI\u3002<\/li>\n<li>pingora-openssl\u548cpingora-boringssl&#xff1a;SSL\u76f8\u5173\u7684\u6269\u5c55\u548cAPI\u3002<\/li>\n<li>pingora-ketama&#xff1a;\u5b9e\u73b0\u4e00\u81f4\u6027\u54c8\u5e0c\u7b97\u6cd5Ketama\u3002<\/li>\n<li>pingora-limits&#xff1a;\u9ad8\u6548\u7684\u8ba1\u6570\u7b97\u6cd5\u3002<\/li>\n<li>pingora-load-balancing&#xff1a;pingora-proxy\u7684\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\u6269\u5c55\u3002<\/li>\n<li>pingora-memory-cache&#xff1a;\u5e26\u6709\u7f13\u5b58\u9501\u7684\u5f02\u6b65\u5185\u5b58\u7f13\u5b58&#xff0c;\u9632\u6b62\u7f13\u5b58\u8e29\u8e0f\u95ee\u9898\u3002<\/li>\n<li>pingora-timeout&#xff1a;\u66f4\u9ad8\u6548\u7684\u5f02\u6b65\u5b9a\u65f6\u5668\u7cfb\u7edf\u3002<\/li>\n<h4>\u56db\u3001\u5e94\u7528\u573a\u666f<\/h4>\n<p>Pingora\u4e3b\u8981\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u6027\u80fd\u3001\u9ad8\u53ef\u9760\u6027\u548c\u9ad8\u53ef\u7f16\u7a0b\u6027\u7684\u7f51\u7edc\u670d\u52a1\u573a\u666f&#xff0c;\u5982\u4e91\u8ba1\u7b97\u3001\u8fb9\u7f18\u8ba1\u7b97\u3001\u7269\u8054\u7f51\u7b49\u3002\u5b83\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u6784\u5efa\u548c\u8fed\u4ee3\u7f51\u7edc\u670d\u52a1&#xff0c;\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u670d\u52a1\u8d28\u91cf\u3002<\/p>\n<h4>\u4e94\u3001\u4f7f\u7528\u4e0e\u793e\u533a<\/h4>\n<li>\u4f7f\u7528&#xff1a;\u8981\u5f00\u59cb\u4f7f\u7528Pingora&#xff0c;\u9996\u5148\u9700\u8981\u5b89\u88c5Rust 1.72\u6216\u66f4\u9ad8\u7248\u672c&#xff0c;\u4ee5\u53caClang\u548cPerl 5\u7528\u4e8e\u7279\u5b9a\u5e93\u7684\u6784\u5efa\u3002\u7136\u540e&#xff0c;\u53ef\u4ee5\u4ecePingora\u7684\u5b98\u65b9\u9879\u76ee\u5730\u5740&#xff08;https:\/\/gitcode.com\/gh_mirrors\/pi\/pingora&#xff09;\u4e0b\u8f7d\u5e76\u7f16\u8bd1\u6e90\u7801\u3002Pingora\u63d0\u4f9b\u4e86\u8be6\u7ec6\u7684\u5feb\u901f\u542f\u52a8\u6307\u5357\u548c\u7528\u6237\u6307\u5357&#xff0c;\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u4e0a\u624b\u548c\u6df1\u5165\u914d\u7f6e\u3002<\/li>\n<li>\u793e\u533a&#xff1a;Pingora\u62e5\u6709\u4e00\u4e2a\u6d3b\u8dc3\u7684\u793e\u533a&#xff0c;\u805a\u96c6\u4e86\u4f17\u591a\u6280\u672f\u7231\u597d\u8005\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u52a0\u5165\u793e\u533a&#xff0c;\u4e0e\u4ed6\u4eba\u4ea4\u6d41\u5206\u4eab&#xff0c;\u5171\u540c\u5b66\u4e60\u8fdb\u6b65\u3002<\/li>\n<p>\u7efc\u4e0a\u6240\u8ff0&#xff0c;Pingora\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u3001\u6613\u4e8e\u4f7f\u7528\u7684\u7f51\u7edc\u670d\u52a1\u6784\u5efa\u5de5\u5177&#xff0c;\u5b83\u4ee5\u5176\u9ad8\u6027\u80fd\u3001\u591a\u534f\u8bae\u652f\u6301\u3001\u4f18\u96c5\u91cd\u542f\u673a\u5236\u548c\u9ad8\u53ef\u7f16\u7a0b\u6027\u7b49\u7279\u70b9&#xff0c;\u8d62\u5f97\u4e86\u5f00\u53d1\u8005\u7684\u5e7f\u6cdb\u8d5e\u8a89\u3002<\/p>\n<h3>\u5feb\u901f\u6784\u5efa\u4e00\u4e2a\u8d1f\u8f7d\u5747\u8861\u5668<\/h3>\n<p>\u5982\u4f55\u4f7f\u7528 pingora \u548c pingora-proxy \u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u3002<\/p>\n<p>\u8d1f\u8f7d\u5747\u8861\u5668\u7684\u76ee\u6807\u662f\u9488\u5bf9\u6bcf\u4e2a\u4f20\u5165\u7684 HTTP \u8bf7\u6c42&#xff0c;\u4ee5\u5faa\u73af\u65b9\u5f0f\u9009\u62e9\u4e24\u4e2a\u540e\u7aef\u4e4b\u4e00&#xff1a;https:\/\/1.1.1.1\u548chttps:\/\/1.0.0.1 \u3002<\/p>\n<h4>\u6784\u5efa\u57fa\u672c\u8d1f\u8f7d\u5747\u8861\u5668<\/h4>\n<p>\u4e3a\u6211\u4eec\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Cargo \u9879\u76ee\u3002\u6211\u4eec\u79f0\u4e4b\u4e3aload_balancer<\/p>\n<p>cargo new load_balancer<\/p>\n<p>\u5305\u62ec Pingora Crate \u548c\u57fa\u672c\u4f9d\u8d56\u9879 \u5728\u60a8\u7684\u9879\u76eecargo.toml\u6587\u4ef6\u4e2d\u5c06\u4ee5\u4e0b\u5185\u5bb9\u6dfb\u52a0\u5230\u60a8\u7684\u4f9d\u8d56\u9879\u4e2d<\/p>\n<p><span class=\"token keyword\">async<\/span><span class=\"token operator\">&#8211;<\/span><span class=\"token keyword\">trait<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;0.1&#034;<\/span><br \/>\npingora <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> version <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;0.1&#034;<\/span><span class=\"token punctuation\">,<\/span> features <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span> <span class=\"token string\">&#034;lb&#034;<\/span> <span class=\"token punctuation\">]<\/span> <span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u521b\u5efa pingora \u670d\u52a1\u5668<\/h4>\n<p>\u9996\u5148&#xff0c;\u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2a pingora \u670d\u52a1\u5668\u3002pingoraServer\u662f\u4e00\u4e2a\u53ef\u4ee5\u6258\u7ba1\u4e00\u4e2a\u6216\u591a\u4e2a\u670d\u52a1\u7684\u8fdb\u7a0b\u3002pingoraServer\u8d1f\u8d23\u914d\u7f6e\u548c CLI \u53c2\u6570\u89e3\u6790\u3001\u5b88\u62a4\u8fdb\u7a0b\u3001\u4fe1\u53f7\u5904\u7406\u4ee5\u53ca\u6b63\u5e38\u91cd\u542f\u6216\u5173\u95ed\u3002<\/p>\n<p>Server\u9996\u9009\u7528\u6cd5\u662f\u5728\u51fd\u6570\u4e2d\u521d\u59cb\u5316main()\u5e76\u7528\u6765run_forever()\u751f\u6210\u6240\u6709\u8fd0\u884c\u65f6\u7ebf\u7a0b\u5e76\u963b\u6b62\u4e3b\u7ebf\u7a0b\u76f4\u5230\u670d\u52a1\u5668\u51c6\u5907\u9000\u51fa\u3002<\/p>\n<p><span class=\"token keyword\">use<\/span> <span class=\"token namespace\">async_trait<span class=\"token punctuation\">::<\/span><\/span>async_trait<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">use<\/span> <span class=\"token namespace\">pingora<span class=\"token punctuation\">::<\/span>prelude<span class=\"token punctuation\">::<\/span><\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">use<\/span> <span class=\"token namespace\">std<span class=\"token punctuation\">::<\/span>sync<span class=\"token punctuation\">::<\/span><\/span><span class=\"token class-name\">Arc<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">fn<\/span> <span class=\"token function-definition function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> <span class=\"token keyword\">mut<\/span> my_server <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">Server<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">new<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">None<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">unwrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    my_server<span class=\"token punctuation\">.<\/span><span class=\"token function\">bootstrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    my_server<span class=\"token punctuation\">.<\/span><span class=\"token function\">run_forever<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u521b\u5efa\u8d1f\u8f7d\u5747\u8861\u5668\u4ee3\u7406<\/h4>\n<p>\u63a5\u4e0b\u6765\u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u8d1f\u8f7d\u5747\u8861\u5668\u3002\u6211\u4eec\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u5305\u542b\u4e00\u4e2a\u9759\u6001\u4e0a\u6e38 IP \u5217\u8868\u3002cratepingora-load-balancing\u5df2\u7ecf\u4e3aLoadBalancer\u7ed3\u6784\u63d0\u4f9b\u4e86\u5e38\u89c1\u7684\u9009\u62e9\u7b97\u6cd5&#xff0c;\u4f8b\u5982\u5faa\u73af\u548c\u54c8\u5e0c\u3002\u6240\u4ee5\u6211\u4eec\u5c31\u4f7f\u7528\u5b83\u5427\u3002\u5982\u679c\u7528\u4f8b\u9700\u8981\u66f4\u590d\u6742\u6216\u5b9a\u5236\u7684\u670d\u52a1\u5668\u9009\u62e9\u903b\u8f91&#xff0c;\u7528\u6237\u53ef\u4ee5\u7b80\u5355\u5730\u5728\u6b64\u51fd\u6570\u4e2d\u81ea\u5df1\u5b9e\u73b0\u5b83\u3002<\/p>\n<p><span class=\"token keyword\">pub<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token type-definition class-name\">LB<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Arc<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token class-name\">LoadBalancer<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token class-name\">RoundRobin<\/span><span class=\"token operator\">&gt;&gt;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4e3a\u4e86\u4f7f\u670d\u52a1\u5668\u6210\u4e3a\u4ee3\u7406&#xff0c;\u6211\u4eec\u9700\u8981ProxyHttp\u4e3a\u5176\u5b9e\u73b0\u7279\u5f81\u3002<\/p>\n<p>\u4efb\u4f55\u5b9e\u73b0\u8be5ProxyHttp\u7279\u5f81\u7684\u5bf9\u8c61\u672c\u8d28\u4e0a\u90fd\u5b9a\u4e49\u4e86\u5982\u4f55\u5728\u4ee3\u7406\u4e2d\u5904\u7406\u8bf7\u6c42\u3002\u8be5ProxyHttp\u7279\u5f81\u4e2d\u552f\u4e00\u5fc5\u9700\u7684\u65b9\u6cd5\u662fupstream_peer()\u8fd4\u56de\u5e94\u5c06\u8bf7\u6c42\u4ee3\u7406\u5230\u7684\u5730\u5740\u3002<\/p>\n<p>\u5728 \u7684\u4e3b\u4f53\u4e2dupstream_peer()&#xff0c;\u6211\u4eec\u4f7f\u7528 \u7684select()\u65b9\u6cd5LoadBalancer\u5728\u4e0a\u6e38 IP \u4e4b\u95f4\u8fdb\u884c\u5faa\u73af\u3002\u5728\u6b64\u793a\u4f8b\u4e2d&#xff0c;\u6211\u4eec\u4f7f\u7528 HTTPS \u8fde\u63a5\u5230\u540e\u7aef&#xff0c;\u56e0\u6b64\u5728\u6784\u9020 ) \u5bf9\u8c61\u65f6&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u6307\u5b9ause_tls\u5e76\u8bbe\u7f6e SNI Peer\u3002<\/p>\n<p><span class=\"token attribute attr-name\">#[async_trait]<\/span><br \/>\n<span class=\"token keyword\">impl<\/span> <span class=\"token class-name\">ProxyHttp<\/span> <span class=\"token keyword\">for<\/span> <span class=\"token constant\">LB<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/\/ For this small example, we don&#039;t need context storage<\/span><br \/>\n    <span class=\"token keyword\">type<\/span> <span class=\"token constant\">CTX<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">fn<\/span> <span class=\"token function-definition function\">new_ctx<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span><span class=\"token keyword\">self<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">-&gt;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">async<\/span> <span class=\"token keyword\">fn<\/span> <span class=\"token function-definition function\">upstream_peer<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span><span class=\"token keyword\">self<\/span><span class=\"token punctuation\">,<\/span> _session<span class=\"token punctuation\">:<\/span> <span class=\"token operator\">&amp;<\/span><span class=\"token keyword\">mut<\/span> <span class=\"token class-name\">Session<\/span><span class=\"token punctuation\">,<\/span> _ctx<span class=\"token punctuation\">:<\/span> <span class=\"token operator\">&amp;<\/span><span class=\"token keyword\">mut<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">-&gt;<\/span> <span class=\"token class-name\">Result<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token class-name\">Box<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token class-name\">HttpPeer<\/span><span class=\"token operator\">&gt;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">let<\/span> upstream <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">self<\/span><span class=\"token punctuation\">.<\/span><span class=\"token number\">0<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">select<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">b&#034;&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">256<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\">\/\/ hash doesn&#039;t matter for round robin<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">unwrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token macro property\">println!<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;upstream peer is: {upstream:?}&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ Set SNI to one.one.one.one<\/span><br \/>\n        <span class=\"token keyword\">let<\/span> peer <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">Box<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">new<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">HttpPeer<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">new<\/span><span class=\"token punctuation\">(<\/span>upstream<span class=\"token punctuation\">,<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;one.one.one.one&#034;<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">to_string<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">Ok<\/span><span class=\"token punctuation\">(<\/span>peer<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e3a\u4e86\u8ba9 1.1.1.1 \u540e\u7aef\u63a5\u53d7\u6211\u4eec\u7684\u8bf7\u6c42&#xff0c;\u5fc5\u987b\u5b58\u5728\u4e3b\u673a\u6807\u5934\u3002\u53ef\u4ee5\u901a\u8fc7\u56de\u8c03\u6dfb\u52a0\u6b64\u6807\u5934&#xff0c;upstream_request_filter()\u8be5\u56de\u8c03\u4f1a\u5728\u4e0e\u540e\u7aef\u5efa\u7acb\u8fde\u63a5\u4e4b\u540e\u3001\u53d1\u9001\u8bf7\u6c42\u6807\u5934\u4e4b\u524d\u4fee\u6539\u8bf7\u6c42\u6807\u5934\u3002<\/p>\n<p><span class=\"token keyword\">impl<\/span> <span class=\"token class-name\">ProxyHttp<\/span> <span class=\"token keyword\">for<\/span> <span class=\"token constant\">LB<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n    <span class=\"token keyword\">async<\/span> <span class=\"token keyword\">fn<\/span> <span class=\"token function-definition function\">upstream_request_filter<\/span><span class=\"token punctuation\">(<\/span><br \/>\n        <span class=\"token operator\">&amp;<\/span><span class=\"token keyword\">self<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        _session<span class=\"token punctuation\">:<\/span> <span class=\"token operator\">&amp;<\/span><span class=\"token keyword\">mut<\/span> <span class=\"token class-name\">Session<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        upstream_request<span class=\"token punctuation\">:<\/span> <span class=\"token operator\">&amp;<\/span><span class=\"token keyword\">mut<\/span> <span class=\"token class-name\">RequestHeader<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        _ctx<span class=\"token punctuation\">:<\/span> <span class=\"token operator\">&amp;<\/span><span class=\"token keyword\">mut<\/span> <span class=\"token keyword\">Self<\/span><span class=\"token punctuation\">::<\/span><span class=\"token constant\">CTX<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">-&gt;<\/span> <span class=\"token class-name\">Result<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        upstream_request<span class=\"token punctuation\">.<\/span><span class=\"token function\">insert_header<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Host&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;one.one.one.one&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">unwrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">Ok<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u521b\u5efa pingora-proxy \u670d\u52a1<\/h4>\n<p>\u63a5\u4e0b\u6765\u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u9075\u5faa\u4e0a\u8ff0\u8d1f\u8f7d\u5747\u8861\u5668\u7684\u6307\u793a\u7684\u4ee3\u7406\u670d\u52a1\u3002<\/p>\n<p>pingoraService\u76d1\u542c\u4e00\u4e2a\u6216\u591a\u4e2a&#xff08;TCP \u6216 Unix \u57df\u5957\u63a5\u5b57&#xff09;\u7aef\u70b9\u3002\u5efa\u7acb\u65b0\u8fde\u63a5\u65f6&#xff0c;\u5c06Service\u8fde\u63a5\u79fb\u4ea4\u7ed9\u5176\u201c\u5e94\u7528\u7a0b\u5e8f\u201d\u3002pingora-proxy\u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u5b83\u5c06 HTTP \u8bf7\u6c42\u4ee3\u7406\u5230\u4e0a\u9762\u914d\u7f6e\u7684\u7ed9\u5b9a\u540e\u7aef\u3002<\/p>\n<p>\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d&#xff0c;\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2aLB\u6709\u4e24\u4e2a\u540e\u7aef\u7684\u5b9e\u4f8b1.1.1.1:443\u548c1.0.0.1:443\u3002\u6211\u4eec\u901a\u8fc7\u8c03\u7528 \u5c06\u8be5LB\u5b9e\u4f8b\u653e\u5230\u4ee3\u7406\u4e2d&#xff0c;\u7136\u540e\u544a\u8bc9\u6211\u4eec \u6258\u7ba1\u8be5\u4ee3\u7406\u3002Servicehttp_proxy_service()ServerService<\/p>\n<p><span class=\"token keyword\">fn<\/span> <span class=\"token function-definition function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> <span class=\"token keyword\">mut<\/span> my_server <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">Server<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">new<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">None<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">unwrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    my_server<span class=\"token punctuation\">.<\/span><span class=\"token function\">bootstrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">let<\/span> upstreams <span class=\"token operator\">&#061;<\/span><br \/>\n        <span class=\"token class-name\">LoadBalancer<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">try_from_iter<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;1.1.1.1:443&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;1.0.0.1:443&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">unwrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">let<\/span> <span class=\"token keyword\">mut<\/span> lb <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">http_proxy_service<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>my_server<span class=\"token punctuation\">.<\/span>configuration<span class=\"token punctuation\">,<\/span> <span class=\"token constant\">LB<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Arc<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">new<\/span><span class=\"token punctuation\">(<\/span>upstreams<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        lb<span class=\"token punctuation\">.<\/span><span class=\"token function\">add_tcp<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;0.0.0.0:6188&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    my_server<span class=\"token punctuation\">.<\/span><span class=\"token function\">add_service<\/span><span class=\"token punctuation\">(<\/span>lb<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    my_server<span class=\"token punctuation\">.<\/span><span class=\"token function\">run_forever<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fd0\u884c\u5b83<\/p>\n<p>cargo run<\/p>\n<p>\u4e3a\u4e86\u6d4b\u8bd5\u5b83&#xff0c;\u53ea\u9700\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5411\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e9b\u8bf7\u6c42&#xff1a;<\/p>\n<p><span class=\"token function\">curl<\/span> <span class=\"token number\">127.0<\/span>.0.1:6188 -svo \/dev\/null<\/p>\n<p>\u60a8\u4e5f\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95eehttp:\/\/localhost:6188 \u4ee5\u4e0b\u8f93\u51fa\u663e\u793a\u8d1f\u8f7d\u5747\u8861\u5668\u6b63\u5728\u6267\u884c\u5176\u5de5\u4f5c\u4ee5\u5728\u4e24\u4e2a\u540e\u7aef\u4e4b\u95f4\u8fdb\u884c\u5e73\u8861&#xff1a;<\/p>\n<p>upstream peer is: Backend <span class=\"token punctuation\">{<\/span> addr: Inet<span class=\"token punctuation\">(<\/span>1<span class=\"token punctuation\">.<\/span>0<span class=\"token punctuation\">.<\/span>0<span class=\"token punctuation\">.<\/span>1:443<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> weight: 1 <span class=\"token punctuation\">}<\/span><br \/>\nupstream peer is: Backend <span class=\"token punctuation\">{<\/span> addr: Inet<span class=\"token punctuation\">(<\/span>1<span class=\"token punctuation\">.<\/span>1<span class=\"token punctuation\">.<\/span>1<span class=\"token punctuation\">.<\/span>1:443<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> weight: 1 <span class=\"token punctuation\">}<\/span><br \/>\nupstream peer is: Backend <span class=\"token punctuation\">{<\/span> addr: Inet<span class=\"token punctuation\">(<\/span>1<span class=\"token punctuation\">.<\/span>0<span class=\"token punctuation\">.<\/span>0<span class=\"token punctuation\">.<\/span>1:443<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> weight: 1 <span class=\"token punctuation\">}<\/span><br \/>\nupstream peer is: Backend <span class=\"token punctuation\">{<\/span> addr: Inet<span class=\"token punctuation\">(<\/span>1<span class=\"token punctuation\">.<\/span>1<span class=\"token punctuation\">.<\/span>1<span class=\"token punctuation\">.<\/span>1:443<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> weight: 1 <span class=\"token punctuation\">}<\/span><br \/>\nupstream peer is: Backend <span class=\"token punctuation\">{<\/span> addr: Inet<span class=\"token punctuation\">(<\/span>1<span class=\"token punctuation\">.<\/span>0<span class=\"token punctuation\">.<\/span>0<span class=\"token punctuation\">.<\/span>1:443<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> weight: 1 <span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5230\u6b64\u4e3a\u6b62&#xff0c; \u5df2\u7ecf\u521b\u5efa\u597d\u4e86\u4e00\u4e2a\u529f\u80fd\u9f50\u5168\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u3002\u4e0d\u8fc7&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38 \u57fa\u672c\u7684\u8d1f\u8f7d\u5747\u8861\u5668&#xff0c;\u56e0\u6b64\u4e0b\u4e00\u8282\u5c06\u5f15\u5bfc\u60a8\u4e86\u89e3\u5982\u4f55\u4f7f\u7528\u4e00\u4e9b\u5185\u7f6e\u7684 pingora \u5de5\u5177\u4f7f\u5176\u66f4\u52a0\u5f3a\u5927\u3002<\/p>\n<h3>\u6dfb\u52a0\u529f\u80fd<\/h3>\n<p>Pingora \u63d0\u4f9b\u4e86\u51e0\u4e2a\u5b9e\u7528\u7684\u529f\u80fd&#xff0c;\u53ea\u9700\u51e0\u884c\u4ee3\u7801\u5373\u53ef\u542f\u7528\u548c\u914d\u7f6e\u3002\u8fd9\u4e9b\u529f\u80fd\u5305\u62ec\u7b80\u5355\u7684\u5bf9\u7b49\u5065\u5eb7\u68c0\u67e5&#xff0c;\u4ee5\u53ca\u65e0\u7f1d\u66f4\u65b0\u6b63\u5728\u8fd0\u884c\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u4e14\u4e0d\u4f1a\u9020\u6210\u670d\u52a1\u4e2d\u65ad\u7684\u80fd\u529b\u3002<\/p>\n<h4>\u540c\u884c\u5065\u5eb7\u68c0\u67e5<\/h4>\n<p>\u4e3a\u4e86\u4f7f\u6211\u4eec\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u66f4\u52a0\u53ef\u9760&#xff0c;\u6211\u4eec\u5e0c\u671b\u4e3a\u4e0a\u6e38\u5bf9\u7b49\u70b9\u6dfb\u52a0\u4e00\u4e9b\u5065\u5eb7\u68c0\u67e5\u3002\u8fd9\u6837&#xff0c;\u5982\u679c\u67d0\u4e2a\u5bf9\u7b49\u70b9\u53d1\u751f\u6545\u969c&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5feb\u901f\u505c\u6b62\u5c06\u6d41\u91cf\u8def\u7531\u5230\u8be5\u5bf9\u7b49\u70b9\u3002<\/p>\n<p>\u9996\u5148&#xff0c;\u8ba9\u6211\u4eec\u770b\u770b\u5f53\u5176\u4e2d\u4e00\u4e2a\u5bf9\u7b49\u70b9\u53d1\u751f\u6545\u969c\u65f6&#xff0c;\u6211\u4eec\u7684\u7b80\u5355\u8d1f\u8f7d\u5747\u8861\u5668\u4f1a\u5982\u4f55\u8868\u73b0\u3002\u4e3a\u6b64&#xff0c;\u6211\u4eec\u5c06\u66f4\u65b0\u5bf9\u7b49\u70b9\u5217\u8868&#xff0c;\u4ee5\u5305\u542b\u4e00\u4e2a\u80af\u5b9a\u4f1a\u53d1\u751f\u6545\u969c\u7684\u5bf9\u7b49\u70b9\u3002<\/p>\n<p><span class=\"token keyword\">fn<\/span> <span class=\"token function-definition function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> upstreams <span class=\"token operator\">&#061;<\/span><br \/>\n        <span class=\"token class-name\">LoadBalancer<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">try_from_iter<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;1.1.1.1:443&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;1.0.0.1:443&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;127.0.0.1:343&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">unwrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u73b0\u5728&#xff0c;\u5982\u679c\u6211\u4eec\u518d\u6b21\u4f7f\u7528\u8fd0\u884c\u8d1f\u8f7d\u5747\u8861\u5668cargo run&#xff0c;\u5e76\u4f7f\u7528<\/p>\n<p>curl 127<span class=\"token punctuation\">.<\/span>0<span class=\"token punctuation\">.<\/span>0<span class=\"token punctuation\">.<\/span>1:6188 <span class=\"token operator\">&#8211;<\/span>svo <span class=\"token operator\">\/<\/span>dev<span class=\"token operator\">\/<\/span>null<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230&#xff0c;\u6bcf 3 \u4e2a\u8bf7\u6c42\u4e2d\u5c31\u6709\u4e00\u4e2a\u4f1a\u5931\u8d25502: Bad Gateway\u3002\u8fd9\u662f\u56e0\u4e3a\u6211\u4eec\u7684\u5bf9\u7b49\u70b9\u9009\u62e9\u4e25\u683c\u9075\u5faaRoundRobin\u6211\u4eec\u7ed9\u51fa\u7684\u9009\u62e9\u6a21\u5f0f&#xff0c;\u800c\u6ca1\u6709\u8003\u8651\u8be5\u5bf9\u7b49\u70b9\u662f\u5426\u5065\u5eb7\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u57fa\u672c\u5065\u5eb7\u68c0\u67e5\u670d\u52a1\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p><span class=\"token keyword\">fn<\/span> <span class=\"token function-definition function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> <span class=\"token keyword\">mut<\/span> my_server <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">Server<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">new<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">None<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">unwrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    my_server<span class=\"token punctuation\">.<\/span><span class=\"token function\">bootstrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ Note that upstreams needs to be declared as &#096;mut&#096; now<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> <span class=\"token keyword\">mut<\/span> upstreams <span class=\"token operator\">&#061;<\/span><br \/>\n        <span class=\"token class-name\">LoadBalancer<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">try_from_iter<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;1.1.1.1:443&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;1.0.0.1:443&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;127.0.0.1:343&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">unwrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">let<\/span> hc <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">TcpHealthCheck<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">new<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    upstreams<span class=\"token punctuation\">.<\/span><span class=\"token function\">set_health_check<\/span><span class=\"token punctuation\">(<\/span>hc<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    upstreams<span class=\"token punctuation\">.<\/span>health_check_frequency <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">Some<\/span><span class=\"token punctuation\">(<\/span><span class=\"token namespace\">std<span class=\"token punctuation\">::<\/span>time<span class=\"token punctuation\">::<\/span><\/span><span class=\"token class-name\">Duration<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">from_secs<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">let<\/span> background <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">background_service<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;health check&#034;<\/span><span class=\"token punctuation\">,<\/span> upstreams<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> upstreams <span class=\"token operator\">&#061;<\/span> background<span class=\"token punctuation\">.<\/span><span class=\"token function\">task<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ &#096;upstreams&#096; no longer need to be wrapped in an arc<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> <span class=\"token keyword\">mut<\/span> lb <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">http_proxy_service<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>my_server<span class=\"token punctuation\">.<\/span>configuration<span class=\"token punctuation\">,<\/span> <span class=\"token constant\">LB<\/span><span class=\"token punctuation\">(<\/span>upstreams<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    lb<span class=\"token punctuation\">.<\/span><span class=\"token function\">add_tcp<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;0.0.0.0:6188&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    my_server<span class=\"token punctuation\">.<\/span><span class=\"token function\">add_service<\/span><span class=\"token punctuation\">(<\/span>background<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    my_server<span class=\"token punctuation\">.<\/span><span class=\"token function\">add_service<\/span><span class=\"token punctuation\">(<\/span>lb<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    my_server<span class=\"token punctuation\">.<\/span><span class=\"token function\">run_forever<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u73b0\u5728&#xff0c;\u5982\u679c\u6211\u4eec\u518d\u6b21\u8fd0\u884c\u5e76\u6d4b\u8bd5\u6211\u4eec\u7684\u8d1f\u8f7d\u5747\u8861\u5668&#xff0c;\u6211\u4eec\u4f1a\u770b\u5230\u6240\u6709\u8bf7\u6c42\u90fd\u6210\u529f&#xff0c;\u5e76\u4e14\u4ece\u672a\u4f7f\u7528\u8fc7\u635f\u574f\u7684\u5bf9\u7b49\u70b9\u3002\u6839\u636e\u6211\u4eec\u4f7f\u7528\u7684\u914d\u7f6e&#xff0c;\u5982\u679c\u8be5\u5bf9\u7b49\u70b9\u518d\u6b21\u6062\u590d\u6b63\u5e38&#xff0c;\u5b83\u5c06\u5728 1 \u79d2\u5185\u518d\u6b21\u91cd\u65b0\u7eb3\u5165\u5faa\u73af\u4e2d\u3002<\/p>\n<h4>\u547d\u4ee4\u884c\u9009\u9879<\/h4>\n<p>pingoraServer\u7c7b\u578b\u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u529f\u80fd&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5355\u884c\u66f4\u6539\u6765\u5229\u7528\u8fd9\u4e9b\u529f\u80fd\u3002<\/p>\n<p><span class=\"token keyword\">fn<\/span> <span class=\"token function-definition function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> <span class=\"token keyword\">mut<\/span> my_server <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">Server<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">new<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Some<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Opt<\/span><span class=\"token punctuation\">::<\/span><span class=\"token function\">parse_args<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">unwrap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">&#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u901a\u8fc7\u6b64\u66f4\u6539&#xff0c;\u4f20\u9012\u7ed9\u6211\u4eec\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u7684\u547d\u4ee4\u884c\u53c2\u6570\u5c06\u88ab Pingora \u4f7f\u7528\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6d4b\u8bd5&#xff1a;<\/p>\n<p>cargo run <span class=\"token operator\">&#8212;<\/span> <span class=\"token operator\">&#8211;<\/span>h<\/p>\n<p>\u6211\u4eec\u5e94\u8be5\u770b\u5230\u4e00\u4e2a\u5e2e\u52a9\u83dc\u5355&#xff0c;\u5176\u4e2d\u5217\u51fa\u4e86\u73b0\u5728\u53ef\u7528\u7684\u53c2\u6570\u3002\u6211\u4eec\u5c06\u5728\u4e0b\u4e00\u8282\u4e2d\u5229\u7528\u8fd9\u4e9b\u53c2\u6570&#xff0c;\u514d\u8d39\u4f7f\u7528\u6211\u4eec\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u505a\u66f4\u591a\u4e8b\u60c5<\/p>\n<h4>\u5728\u540e\u53f0\u8fd0\u884c<\/h4>\n<p>\u4f20\u9012\u53c2\u6570-d\u6216\u2013daemon\u5c06\u544a\u8bc9\u7a0b\u5e8f\u5728\u540e\u53f0\u8fd0\u884c\u3002<\/p>\n<p>cargo run <span class=\"token operator\">&#8212;<\/span> <span class=\"token operator\">&#8211;<\/span>d<\/p>\n<p>\u8981\u505c\u6b62\u6b64\u670d\u52a1&#xff0c;\u60a8\u53ef\u4ee5SIGTERM\u5411\u5176\u53d1\u9001\u4fe1\u53f7\u4ee5\u8fdb\u884c\u6b63\u5e38\u5173\u95ed&#xff0c;\u6b64\u65f6\u8be5\u670d\u52a1\u5c06\u505c\u6b62\u63a5\u53d7\u65b0\u8bf7\u6c42&#xff0c;\u4f46\u4f1a\u5c1d\u8bd5\u5728\u9000\u51fa\u4e4b\u524d\u5b8c\u6210\u6240\u6709\u6b63\u5728\u8fdb\u884c\u7684\u8bf7\u6c42\u3002<\/p>\n<p><span class=\"token function\">pkill<\/span> -SIGTERM load_balancer<\/p>\n<p>&#xff08;SIGTERM\u662f \u7684\u9ed8\u8ba4\u4fe1\u53f7pkill\u3002&#xff09;<\/p>\n<h4>\u914d\u7f6e<\/h4>\n<p>Pingora \u914d\u7f6e\u6587\u4ef6\u6709\u52a9\u4e8e\u5b9a\u4e49\u5982\u4f55\u8fd0\u884c\u670d\u52a1\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u914d\u7f6e\u6587\u4ef6&#xff0c;\u5b83\u5b9a\u4e49\u4e86\u670d\u52a1\u53ef\u4ee5\u6709\u591a\u5c11\u4e2a\u7ebf\u7a0b\u3001pid \u6587\u4ef6\u7684\u4f4d\u7f6e\u3001\u9519\u8bef\u65e5\u5fd7\u6587\u4ef6\u548c\u5347\u7ea7\u534f\u8c03\u5957\u63a5\u5b57&#xff08;\u6211\u4eec\u5c06\u5728\u540e\u9762\u89e3\u91ca&#xff09;\u3002\u590d\u5236\u4e0b\u9762\u7684\u5185\u5bb9\u5e76\u5c06\u5176\u653e\u5165\u9879\u76ee\u76ee\u5f55conf.yaml\u4e2d\u540d\u4e3a\u7684\u6587\u4ef6\u4e2dload_balancer\u3002<\/p>\n<p>version: <span class=\"token number\">1<\/span><br \/>\nthreads: <span class=\"token number\">2<\/span><br \/>\npid_file: \/tmp\/load_balancer.pid<br \/>\nerror_log: \/tmp\/load_balancer_err.log<br \/>\nupgrade_sock: \/tmp\/load_balancer.sock<\/p>\n<p>\u8981\u4f7f\u7528\u8be5\u914d\u7f6e\u6587\u4ef6&#xff1a;<\/p>\n<p><span class=\"token assign-left variable\">RUST_LOG<\/span><span class=\"token operator\">&#061;<\/span>INFO cargo run &#8212; -c conf.yaml -d<\/p>\n<p>RUST_LOG&#061;INFO\u662f\u4e3a\u4e86\u8ba9\u670d\u52a1\u771f\u6b63\u586b\u5145\u9519\u8bef\u65e5\u5fd7\u3002<\/p>\n<p>\u73b0\u5728\u60a8\u53ef\u4ee5\u627e\u5230\u670d\u52a1\u7684 pid\u3002<\/p>\n<p> <span class=\"token function\">cat<\/span> \/tmp\/load_balancer.pid<\/p>\n<h4>\u4f18\u96c5\u5730\u5347\u7ea7\u670d\u52a1&#xff08;\u4ec5\u9650 Linux&#xff09;<\/h4>\n<p>\u5047\u8bbe\u6211\u4eec\u66f4\u6539\u4e86\u8d1f\u8f7d\u5747\u8861\u5668\u7684\u4ee3\u7801\u5e76\u91cd\u65b0\u7f16\u8bd1\u4e86\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002\u73b0\u5728\u6211\u4eec\u60f3\u5c06\u540e\u53f0\u8fd0\u884c\u7684\u670d\u52a1\u5347\u7ea7\u5230\u8fd9\u4e2a\u65b0\u7248\u672c\u3002<\/p>\n<p>\u5982\u679c\u6211\u4eec\u53ea\u662f\u505c\u6b62\u65e7\u670d\u52a1&#xff0c;\u7136\u540e\u542f\u52a8\u65b0\u670d\u52a1&#xff0c;\u90a3\u4e48\u4e2d\u95f4\u5230\u8fbe\u7684\u4e00\u4e9b\u8bf7\u6c42\u53ef\u80fd\u4f1a\u4e22\u5931\u3002\u5e78\u8fd0\u7684\u662f&#xff0c;Pingora \u63d0\u4f9b\u4e86\u4e00\u79cd\u4f18\u96c5\u7684\u65b9\u5f0f\u6765\u5347\u7ea7\u670d\u52a1\u3002<\/p>\n<p>\u5b8c\u6210\u6b64\u64cd\u4f5c\u540e&#xff0c;\u9996\u5148SIGQUIT\u5411\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1\u5668\u53d1\u9001\u4fe1\u53f7&#xff0c;\u7136\u540e\u4f7f\u7528\u53c2\u6570-u\\\\\u542f\u52a8\u65b0\u670d\u52a1\u5668\u2013upgrade\u3002<\/p>\n<p><span class=\"token function\">pkill<\/span> -SIGQUIT load_balancer <span class=\"token operator\">&amp;&amp;<\/span><span class=\"token punctuation\">\\\\<\/span><br \/>\n<span class=\"token assign-left variable\">RUST_LOG<\/span><span class=\"token operator\">&#061;<\/span>INFO cargo run &#8212; -c conf.yaml -d -u<\/p>\n<p>\u5728\u6b64\u8fc7\u7a0b\u4e2d&#xff0c;\u65e7\u670d\u52a1\u5668\u5c06\u7b49\u5f85\u5e76\u5c06\u5176\u76d1\u542c\u5957\u63a5\u5b57\u79fb\u4ea4\u7ed9\u65b0\u670d\u52a1\u5668\u3002\u7136\u540e\u65e7\u670d\u52a1\u5668\u5c06\u8fd0\u884c&#xff0c;\u76f4\u5230\u5176\u6240\u6709\u6b63\u5728\u8fdb\u884c\u7684\u8bf7\u6c42\u5b8c\u6210\u3002<\/p>\n<p>\u4ece\u5ba2\u6237\u7aef\u7684\u89d2\u5ea6\u6765\u770b&#xff0c;\u670d\u52a1\u59cb\u7ec8\u5728\u8fd0\u884c&#xff0c;\u56e0\u4e3a\u76d1\u542c\u5957\u63a5\u5b57\u4ece\u672a\u5173\u95ed\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e20\u6b21\uff0c\u6536\u85cf25\u6b21\u3002Pingora\u662f\u4e00\u4e2a\u7528Rust\u7f16\u5199\u7684\u8f6f\u4ef6\u5e93\uff0c\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u6784\u5efa\u5feb\u901f\u3001\u53ef\u9760\u4e14\u6613\u4e8e\u8fed\u4ee3\u5347\u7ea7\u7684\u7f51\u7edc\u670d\u52a1\u3002_pingora<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[868,117,2449,43,867,44],"topic":[],"class_list":["post-30479","post","type-post","status-publish","format-standard","hentry","category-server","tag-868","tag-nginx","tag-pingora","tag-43","tag-867","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u670d\u52a1\u5668\u77e5\u8bc6\u3011nginx\u6027\u80fd\u4e0d\u591f, \u6211\u4eec\u8fd8\u6709pingora - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/30479.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u670d\u52a1\u5668\u77e5\u8bc6\u3011nginx\u6027\u80fd\u4e0d\u591f, \u6211\u4eec\u8fd8\u6709pingora - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e20\u6b21\uff0c\u6536\u85cf25\u6b21\u3002Pingora\u662f\u4e00\u4e2a\u7528Rust\u7f16\u5199\u7684\u8f6f\u4ef6\u5e93\uff0c\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u6784\u5efa\u5feb\u901f\u3001\u53ef\u9760\u4e14\u6613\u4e8e\u8fed\u4ee3\u5347\u7ea7\u7684\u7f51\u7edc\u670d\u52a1\u3002_pingora\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/30479.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-20T12:41:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250420124104-6804eb60cdf42.webp\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/30479.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/30479.html\",\"name\":\"\u3010\u670d\u52a1\u5668\u77e5\u8bc6\u3011nginx\u6027\u80fd\u4e0d\u591f, \u6211\u4eec\u8fd8\u6709pingora - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-20T12:41:05+00:00\",\"dateModified\":\"2025-04-20T12:41:05+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/30479.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/30479.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/30479.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u670d\u52a1\u5668\u77e5\u8bc6\u3011nginx\u6027\u80fd\u4e0d\u591f, \u6211\u4eec\u8fd8\u6709pingora\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010\u670d\u52a1\u5668\u77e5\u8bc6\u3011nginx\u6027\u80fd\u4e0d\u591f, \u6211\u4eec\u8fd8\u6709pingora - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/30479.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u670d\u52a1\u5668\u77e5\u8bc6\u3011nginx\u6027\u80fd\u4e0d\u591f, \u6211\u4eec\u8fd8\u6709pingora - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e20\u6b21\uff0c\u6536\u85cf25\u6b21\u3002Pingora\u662f\u4e00\u4e2a\u7528Rust\u7f16\u5199\u7684\u8f6f\u4ef6\u5e93\uff0c\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u6784\u5efa\u5feb\u901f\u3001\u53ef\u9760\u4e14\u6613\u4e8e\u8fed\u4ee3\u5347\u7ea7\u7684\u7f51\u7edc\u670d\u52a1\u3002_pingora","og_url":"https:\/\/www.wsisp.com\/helps\/30479.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-20T12:41:05+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250420124104-6804eb60cdf42.webp"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/30479.html","url":"https:\/\/www.wsisp.com\/helps\/30479.html","name":"\u3010\u670d\u52a1\u5668\u77e5\u8bc6\u3011nginx\u6027\u80fd\u4e0d\u591f, \u6211\u4eec\u8fd8\u6709pingora - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-20T12:41:05+00:00","dateModified":"2025-04-20T12:41:05+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/30479.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/30479.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/30479.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u670d\u52a1\u5668\u77e5\u8bc6\u3011nginx\u6027\u80fd\u4e0d\u591f, \u6211\u4eec\u8fd8\u6709pingora"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/30479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=30479"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/30479\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=30479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=30479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=30479"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=30479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}