{"id":1562,"date":"2024-07-30T10:18:27","date_gmt":"2024-07-30T02:18:27","guid":{"rendered":"https:\/\/aichh.com\/?p=1562"},"modified":"2024-07-30T10:18:27","modified_gmt":"2024-07-30T02:18:27","slug":"%e5%88%a9%e7%94%a8-haproxy-%e8%ae%a9-nginx%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%9c%a8%e5%86%85%e7%bd%91%e7%a9%bf%e9%80%8f%e5%90%8e%e8%8e%b7%e5%8f%96%e5%ae%a2%e6%88%b7%e7%ab%af%e7%9c%9f%e5%ae%9e-ip","status":"publish","type":"post","link":"https:\/\/aichh.com\/1562.html","title":{"rendered":"\u5229\u7528 HAProxy \u8ba9 nginx\u670d\u52a1\u5668\u5728\u5185\u7f51\u7a7f\u900f\u540e\u83b7\u53d6\u5ba2\u6237\u7aef\u771f\u5b9e IP"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression--><p>\u5185\u7f51\u7a7f\u900f\u5de5\u5177\u662fnps\uff0c\u56e0\u4e3anps\u4e0d\u652f\u6301Proxy Protocol\u534f\u8bae\uff0c\u6240\u4ee5\u8fd8\u9700\u8981haproxy\u3002\u5982\u679c\u4f7f\u7528frp\u7684\u8bdd\u5219\u4e0d\u9700\u8981haproxy\uff0cfrp\u539f\u751f\u652f\u6301Proxy Protocol\u534f\u8bae\uff0c\u7406\u8bba\u4e0a\u4e0d\u652f\u6301Proxy Protocol\u534f\u8bae\u7684\u7a7f\u900f\u5de5\u5177\u90fd\u53ef\u4ee5\u52a0\u4e00\u7ea7HA\u6765\u83b7\u53d6\u771f\u5b9eIP\u3002<\/p>\n<p>\u6211\u7684\u5b89\u6392\u662f\u8fd9\u6837\u5b50\u7684\uff0c\u5927\u5bb6\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b<\/p>\n<hr \/>\n<p><span data-backcolor=\"#4bb8ff\">VPS\u670d\u52a1\u5668\u4e0a\u7684<\/span><strong><span data-backcolor=\"#e62828\">443\u7aef\u53e3<\/span>\uff0c<\/strong>haproxy\u76d1\u542c<strong><span data-backcolor=\"#e62828\">443\u7aef\u53e3<\/span><\/strong>\uff0c\u52a0\u4e0a\u7528\u6237\u771f\u5b9eip\u540e\u8f6c\u53d1\u7ed9nps\u76d1\u542c\u7684<strong><span data-backcolor=\"#e62828\">3443\u7aef\u53e3<\/span><\/strong><\/p>\n<hr \/>\n<p>\u5185\u7f51\u7a7f\u900f\u672c\u5730nginx 443\u7aef\u53e3\u5230VPS\u4e0a\u76843443\u7aef\u53e3\uff0c\u501f\u4e00\u5f20\u56fe\uff0c\u5927\u6982\u5c31\u8fd9\u6837\u5b50\uff0c\u968f\u4fbf\u770b\u770b\u5427\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"3\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2024\/07\/3.png\" width=\"949\" height=\"822\"><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u5b89\u88c5haproxy<\/strong><\/p>\n<p>\u4e3b\u6d41\u7684linux\u53d1\u884c\u7248\u7684\u8f6f\u4ef6\u4ed3\u5e93\u90fd\u6536\u5f55\u4e86haproxy\uff0c\u53ea\u9700\u8981\u4e00\u6761\u547d\u4ee4\u5c31\u53ef\u4ee5\u5b89\u88c5haproxy\u4e86\u3002<\/p>\n<p>\u5bf9\u4e8eubuntu\/debian\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5b89\u88c5<\/p>\n<p><strong>apt update &amp;&amp; apt upgrade &amp;&amp; apt install haproxy<\/strong><\/p>\n<p>\u5bf9\u4e8ecentos\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5b89\u88c5<\/p>\n<p><strong>yum install epel-release -ysudo yum update -y &amp;&amp; yum install haproxy -y<\/strong><\/p>\n<p>\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u7f16\u8f91haproyx\u7684\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><strong>vim \/etc\/haproxy\/haproxy.cfg<\/strong><\/p>\n<p>\u6309\u201ci\u201d\u952e\u8fdb\u5165\u7f16\u8f91\u6a21\u5f0f\uff0c\u5728\u6587\u4ef6\u7684\u6700\u540e\u9762\u63d2\u5165\u4e0b\u9762\u7684\u5185\u5bb9\uff0c\u8981\u6839\u636e\u7684\u81ea\u5df1\u7684\u5b9e\u9645\u60c5\u51b5\u66f4\u6539\u3002<\/p>\n<pre>listen webhttp\r\n    # haproxy\u76d1\u542c\u7684\u7aef\u53e380\u3001443\uff0c\u6839\u636e\u6211\u7684\u7aef\u53e3\u89c4\u5212\u786e\u5b9a\u7684\r\n    bind 0.0.0.0:80\r\n    mode tcp\r\n    option forwardfor\r\n    #haproxy\u8f6c\u53d1\u7ed9nps\u76d1\u542c\u7684443\u7aef\u53e3\r\n    server webhttp1 127.0.0.1:8080 send-proxy check inter 3000 fall 3 rise 5\r\n\r\nlisten webhttps\r\n    bind 0.0.0.0:443\r\n    mode tcp\r\n    option forwardfor\r\n    server webhttps1 127.0.0.1:3443 send-proxy check inter 3000 fall 3 rise 5\r\n\r\n#\u8f6c\u53d1\u6211\u7684\u4e16\u754c\u52302556\u7aef\u53e3\r\nlisten minecraft\r\n        bind *:25565\r\n        mode tcp\r\n        balance leastconn\r\n        option tcp-check\r\n        server minecraft1 127.0.0.1:2556 send-proxy<\/pre>\n<p>\u4fdd\u5b58\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u8fd0\u884c\u4e0b\u9762\u547d\u4ee4\u542f\u52a8\u548c\u91cd\u542fhaproxy<\/p>\n<hr \/>\n<p><strong>systemctl start haproxy<\/strong><\/p>\n<p><strong>systemctl restart haproxy<\/strong><\/p>\n<hr \/>\n<p>\u7136\u540e\u8fd0\u884c\u4e0b\u9762\u547d\u4ee4\u68c0\u67e5haproxy\u662f\u5426\u8fd0\u884c\uff0c\u5982\u679c\u8f93\u51fa\u4e0b\u56fe\u5185\u5bb9\u5219\u914d\u7f6e\u88ab\u5e94\u7528\u3002<\/p>\n<p><strong>systemctl status haproxy<\/strong><\/p>\n<p><strong>\u914d\u7f6enginx\uff0c\u7f16\u8f91conf\u6587\u4ef6\u52a0\u5165\u4ee5\u4e0b\u5185\u5bb9<\/strong><\/p>\n<pre>server\r\n{\r\n    listen 80 proxy_protocol; #proxy_protocol\r\n    listen 443 ssl proxy_protocol; #proxy_protocol\r\n\t\r\n\t......\u5176\u4ed6\u4ee3\u7801......\r\n\r\n\t# \u5f00\u542f\u6392\u9664IP\u529f\u80fd\r\n    real_ip_recursive on;\r\n \t# \u6392\u9664\u672c\u5730ip\r\n    set_real_ip_from 192.168.0.0\/24;\r\n    set_real_ip_from 127.0.0.1;\r\n    #CF \u5730\u5740https:\/\/www.cloudflare-cn.com\/ips\/\r\n    set_real_ip_from 173.245.48.0\/20;\r\n    set_real_ip_from 103.21.244.0\/22;\r\n    set_real_ip_from 103.22.200.0\/22;\r\n    set_real_ip_from 103.31.4.0\/22;\r\n    set_real_ip_from 141.101.64.0\/18;\r\n    set_real_ip_from 108.162.192.0\/18;\r\n    set_real_ip_from 190.93.240.0\/20;\r\n    set_real_ip_from 188.114.96.0\/20;\r\n    set_real_ip_from 197.234.240.0\/22;\r\n    set_real_ip_from 198.41.128.0\/17;\r\n    set_real_ip_from 162.158.0.0\/15;\r\n    set_real_ip_from 104.16.0.0\/13;\r\n    set_real_ip_from 104.24.0.0\/14;\r\n    set_real_ip_from 172.64.0.0\/13;\r\n    set_real_ip_from 131.0.72.0\/22;\r\n    # \u771f\u5b9eIP\u4f7f\u7528proxy_protocol\u534f\u8bae\r\n    real_ip_header proxy_protocol;\r\n    #real_ip_header X-Real-IP;\r\n\t\r\n\t......\u5176\u4ed6\u4ee3\u7801......\r\n\t\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<p>https:\/\/post.smzdm.com\/p\/a30vrqlk\/<\/p>\n<p>https:\/\/myth.cx\/p\/minecraft-haproxy\/<\/p>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"\u5185\u7f51\u7a7f\u900f\u5de5\u5177\u662fnps\uff0c\u56e0\u4e3anps\u4e0d\u652f\u6301Proxy Protocol\u534f\u8bae\uff0c\u6240\u4ee5\u8fd8\u9700\u8981haproxy\u3002\u5982\u679c\u4f7f\u7528frp\u7684\u8bdd\u5219\u4e0d\u9700\u8981haproxy\uff0cfrp\u539f\u751f\u652f\u6301Proxy Protocol\u534f\u8bae\uff0c\u7406\u8bba\u4e0a\u4e0d\u652f\u6301 \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":1563,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[411,242,57],"class_list":["post-1562","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jiaocheng","tag-haproxy","tag-ip","tag-57"],"views":265,"_links":{"self":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/1562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/comments?post=1562"}],"version-history":[{"count":1,"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/1562\/revisions"}],"predecessor-version":[{"id":1564,"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/1562\/revisions\/1564"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/media\/1563"}],"wp:attachment":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/media?parent=1562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/categories?post=1562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/tags?post=1562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}