{"id":184906,"date":"2020-10-29T16:33:40","date_gmt":"2020-10-29T08:33:40","guid":{"rendered":"http:\/\/4563.org\/?p=184906"},"modified":"2020-10-29T16:33:40","modified_gmt":"2020-10-29T08:33:40","slug":"openresty-%e4%bd%bf%e7%94%a8-ngx_balancer-set_current_peer-%e6%96%b9%e6%b3%95%e4%b8%8d%e8%83%bd%e8%ae%be%e7%bd%ae%e5%9f%9f%e5%90%8d%ef%bc%8c%e9%82%a3%e5%af%b9%e4%ba%8e%e8%bd%ac%e5%8f%91%e5%88%b0","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=184906","title":{"rendered":"OpenResty \u4f7f\u7528 ngx_balancer.set_current_peer() \u65b9\u6cd5\u4e0d\u80fd\u8bbe\u7f6e\u57df\u540d\uff0c\u90a3\u5bf9\u4e8e\u8f6c\u53d1\u5230\u67d0\u4e2a\u57df\u540d\u7684\u60c5\u51b5\u8981\u600e\u4e48\u505a\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  OpenResty \u4f7f\u7528 ngx_balancer.set_current_peer() \u65b9\u6cd5\u4e0d\u80fd\u8bbe\u7f6e\u57df\u540d\uff0c\u90a3\u5bf9\u4e8e\u8f6c\u53d1\u5230\u67d0\u4e2a\u57df\u540d\u7684\u60c5\u51b5\u8981\u600e\u4e48\u505a\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Lpl <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6587\u6863\u5730\u5740\uff1a https:\/\/github.com\/openresty\/lua-resty-core\/blob\/master\/lib\/ngx\/balancer.md#set_current_peer<\/p>\n<pre><code>syntax: ok, err = balancer.set_current_peer(host, port)  context: balancer_by_lua*  Sets the peer address (host and port) for the current backend query (which may be a retry).  Domain names in host do not make sense. You need to use OpenResty libraries like lua-resty-dns to obtain IP address(es) from all the domain names before entering the balancer_by_lua* handler (for example, you can perform DNS lookups in an earlier phase like access_by_lua* and pass the results to the balancer_by_lua* handler via ngx.ctx. <\/code><\/pre>\n<p>\u6309\u7167\u6b63\u5e38 nginx \u7684\u903b\u8f91\uff0cupstream \u4e2d\u662f\u53ef\u4ee5\u5199\u57df\u540d\u7684\u3002\u6b64\u5904 OpenResty \u6587\u6863\u8bf4\u4e0d\u80fd\u5199\u57df\u540d\uff0c\u4f46\u662f\u53ef\u4ee5\u7528 DNS \u628a\u57df\u540d\u7684 IP \u89e3\u6790\u51fa\u6765\u3002<\/p>\n<p>\u89e3\u6790 IP \u7684\u65b9\u5f0f\u5728\u660e\u663e\u4e0d\u7b26\u5408\u9700\u6c42\uff0c\u5047\u5982\u6211\u6709\u4e2a <code>test.com<\/code> \u7684\u57df\u540d\uff0c\u6307\u5411\u4e86\u67d0\u4e2a IP \u3002\u8fd9\u4e2a IP \u662f\u4e2a nginx\uff0c\u6839\u636e server_name \u6765\u533a\u5206\u8bf7\u6c42\u3002\u5982\u679c\u662f\u901a\u8fc7 IP \u8f6c\u53d1\u8fc7\u6765\u7684\u8bf7\u6c42\uff0c\u8bf7\u6c42\u5934\u91cc\u8fb9\u662f\u6ca1\u6709 <code>Host<\/code> \u7684\uff0c\u6240\u4ee5\u8bf7\u6c42\u5e76\u4e0d\u80fd\u6b63\u5e38\u8f6c\u53d1\u3002<\/p>\n<p>\u76ee\u524d\u4e0d\u8003\u8651\u4f7f\u7528 <code>recreate_request<\/code> \u65b9\u6cd5\u6765\u505a\uff0c\u6709\u6ca1\u6709\u4ec0\u4e48\u529e\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>OpenResty \u4f7f\u7528 ngx_&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/184906"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184906"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/184906\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184906"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}