{"id":2122,"date":"2012-09-30T20:43:40","date_gmt":"2012-09-30T12:43:40","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=2122"},"modified":"2013-11-21T18:23:23","modified_gmt":"2013-11-21T10:23:23","slug":"%e9%85%8d%e7%bd%aeapache%e5%92%8cvarnish%e8%8e%b7%e5%8f%96%e7%9c%9f%e5%ae%9e%e6%9d%a5%e6%ba%90ip","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/2122.html","title":{"rendered":"\u914d\u7f6eApache\u548cVarnish\u83b7\u53d6\u771f\u5b9e\u6765\u6e90IP"},"content":{"rendered":"<p>\u5f53\u4f7f\u7528varnish\u505ahttp\u7f13\u5b58\u52a0\u901f\u5668\u7684\u65f6\u5019\uff0c\u540e\u7aefapache\u83b7\u53d6\u7684\u8bf7\u6c42\u4e3avarnish\u53d1\u8fc7\u53bb\u7684\uff0c\u6240\u4ee5\u7528 $_SERVER[&#8216;REMOTE_ADDR&#8217;] \u83b7\u53d6\u5230\u7684IP\u59cb\u7ec8\u4e3a 127.0.0.1\u3002<\/p>\n<p>\u4e0b\u9762\u5bf9apache\u548cvarnish\u914d\u7f6e\uff0c\u4f7fapache\u540e\u7aef\u80fd\u83b7\u53d6\u5230\u771f\u5b9e\u6765\u6e90IP\u3002<\/p>\n<p>\u9996\u5148\u5728varnish\u7684\u914d\u7f6e\u6587\u4ef6\u7684 vcl_recv \u51fd\u6570\u6700\u524d\u9762\u6dfb\u52a0\u5982\u4e0b\u4e00\u53e5\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nsub vcl_recv {\r\n\tset req.http.X-Forwarded-For = client.ip;\r\n}\r\n<\/pre>\n<p>\u6ce8\u610f\u6700\u597d\u662f\u52a0\u5728\u6700\u524d\u9762\uff0c\u9632\u6b62\u8fd9\u53e5\u8bdd\u6ca1\u6267\u884c\u5230\u5c31\u88abpass\u4e86\u3002<\/p>\n<p>\u5bf9\u4e8eapache\u7684\u914d\u7f6e\uff0c\u9700\u8981\u5b89\u88c5\u4e00rpaf\u6269\u5c55\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\napt-get install libapache2-mod-rpaf &amp;&amp; a2enmod rpaf &amp;&amp; apache2ctl graceful\r\n<\/pre>\n<p>\u7136\u540e\u5728apache\u7684\u914d\u7f6e\u6587\u4ef6\uff0cubuntu\u4e2d\u4e3a \/etc\/apache2\/apache2.conf\uff0c\u6dfb\u52a0\u5982\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;IfModule mod_rpaf.c&gt;\r\nRPAFenable On\r\nRPAFsethostname On\r\nRPAFproxy_ips 127.0.0.1\r\n&lt;\/IfModule&gt;\r\n<\/pre>\n<p>\u5176\u4e2dRPAFproxy_ips \u4e3avarnish\u670d\u52a1\u5668\u7684\u5730\u5740\uff0c\u5982\u679c\u6709\u591a\u4e2a\uff0c\u5c31\u5199\u591a\u4e2aIP\uff0c\u5982\uff1aRPAFproxy_ips 127.0.0.1 10.0.0.1<\/p>\n<p>\u6700\u540e\u91cd\u542fapache\u4e0evarnish\uff0c\u5728php\u4e2d\uff0c$_SERVER[&#8216;HTTP_X_FORWARDED_FOR&#8217;] \u5c31\u80fd\u83b7\u53d6\u771f\u5b9e\u7684\u5ba2\u6237\u7aefIP\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$client-&gt;doBackground('sendmsg', $_SERVER&#x5B;'HTTP_X_FORWARDED_FOR']);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u4f7f\u7528varnish\u505ahttp\u7f13\u5b58\u52a0\u901f\u5668\u7684\u65f6\u5019\uff0c\u540e\u7aefapache\u83b7\u53d6\u7684\u8bf7\u6c42\u4e3avarnish\u53d1\u8fc7\u53bb\u7684\uff0c\u6240\u4ee5\u7528 $ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2122","post","type-post","status-publish","format-standard","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=2122"}],"version-history":[{"count":2,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2122\/revisions"}],"predecessor-version":[{"id":5010,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2122\/revisions\/5010"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=2122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=2122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=2122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}