{"id":3335,"date":"2011-12-09T22:37:02","date_gmt":"2011-12-09T14:37:02","guid":{"rendered":"http:\/\/www.orczhou.com\/?p=3335"},"modified":"2011-12-09T22:37:02","modified_gmt":"2011-12-09T14:37:02","slug":"apache-reverse-proxy-with-mod-proxy-html","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2011\/12\/apache-reverse-proxy-with-mod-proxy-html\/","title":{"rendered":"\u4f7f\u7528mod_proxy_html\u5b8c\u5584Apache\u53cd\u5411\u4ee3\u7406"},"content":{"rendered":"<p>\u5728\u4f7f\u7528\u548c\u914d\u7f6e\u8fc7\u7a0b\u4e2d\uff0c\u8fd8\u662f\u9047\u5230\u4e86\u4e00\u4e9b\u6ce2\u6298\uff0c\u8fd9\u91cc\u5206\u4eab\u3001\u8bb0\u5f55\u4e00\u4e0b\u3002<\/p>\n<div class=\"myt1\">1. \u6a21\u5757mod_proxy_html\u53ef\u4ee5\u505a\u4e9b\u4ec0\u4e48<\/div>\n<p>\u4f7f\u7528Apache\u5185\u7f6e\u7684mod_proxy\u7684<a href=\"http:\/\/httpd.apache.org\/docs\/current\/mod\/mod_proxy.html#proxypass\">Proxypass<\/a>\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5b9e\u73b0\u57fa\u672c\u7684<a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/urlmapping.html#proxy\">\u53cd\u5411\u4ee3\u7406<\/a>\u529f\u80fd\u3002\u4f46\u662f\uff0c\u4ee3\u7406\u8fd4\u56de\u7684\u7ed3\u679c\u9875\u9762\u5305\u542b\u7684\u94fe\u63a5\u5e76\u4e0d\u4f1a\u88ab\u91cd\u5199\uff0c\u6240\u4ee5\u5982\u679c\u88ab\u4ee3\u7406\u7684Server\u8fd4\u56de\u7684\u662f\u7edd\u5bf9\u5730\u5740\uff0c\u7528\u6237\u5219\u65e0\u6cd5\u6b63\u786e\u8bbf\u95ee\u8fd9\u4e9b\u94fe\u63a5\u3002\u4f8b\u5982\uff1a<\/p>\n<p>\u6211\u4eec\u6709\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668http:\/\/myproxy.taobao.org\/\uff0c\u800c\u5185\u7f51\u6709\u9700\u8981\u4ee3\u7406\u7684\u670d\u52a1\u5668http:\/\/internalserver.taobao.org\/\uff0c\u901a\u8fc7\u57fa\u672c\u7684\u53cd\u5411\u4ee3\u7406\u6307\u4ee4<a href=\"http:\/\/httpd.apache.org\/docs\/current\/mod\/mod_proxy.html#proxypass\">Proxypass<\/a>\uff1a<\/p>\n<blockquote><p>ProxyPass  ^\/proxy_internal\/(.*)$ http:\/\/internalserver.taobao.org\/$1<\/p><\/blockquote>\n<p>\u53ef\u4ee5\u5b8c\u6210\u57fa\u672c\u7684\u53cd\u5411\u4ee3\u7406\u4efb\u52a1\uff0c\u4f46\u662f\u5982\u679cinternalserver.taobao.org\u8fd4\u56de\u7684HTML\u4ee3\u7801\u4e2d\u6709\u5982\u4e0b\u94fe\u63a5\uff0c\u5219\u5ba2\u6237\u7aef\u5219\u65e0\u6cd5\u6b63\u5e38\u94fe\u63a5\u5230\u76ee\u6807\u9875\u9762\u4e86\uff1a<\/p>\n<blockquote><p>&lt;a href=&#8221;\/test\/index.html&#8221;>Sample Link&lt;\/a><\/p><\/blockquote>\n<p>\u56e0\u4e3a\uff0c\u5ba2\u6237\u7aef\u70b9\u51fb\u8be5\u94fe\u63a5\u65f6\u4f1a\u5b9a\u5411\u5230http:\/\/myproxy.taobao.org\/test\/index.html\uff0c\u800c\u8d44\u6e90\u5b9e\u9645\u662f\u5728http:\/\/internalserver.taobao.org\/test\/index.html\u4e0a\u3002<\/p>\n<p>Apache\u81ea\u5e26\u7684mod_proxy<a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/urlmapping.html#proxy\">\u65e0\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898<\/a>\uff0c\u5f00\u6e90\u7684\u7b2c\u4e09\u65b9\u6a21\u5757<a href=\"http:\/\/apache.webthing.com\/mod_proxy_html\/\">mod_proxy_html<\/a>\u4e3a\u6b64\u800c\u751f\u3002\u7ecf\u8fc7\u4ee3\u7406\u670d\u52a1\u5668\u7684HTML\u53ef\u4ee5\u901a\u8fc7\u8be5\u6a21\u5757\u505a\u4e00\u6b21\u66ff\u6362\uff0c\u4ece\u800c\u53d8\u6210\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\u7684URL\uff08\u4e0a\u4f8b\u4e2d\u4f1a\u628a\/oninternal\/index.html\u66ff\u6362\u6210\/proxy_internal\/test\/index.html\uff09\u3002<br \/>\n<!--more--><\/p>\n<div class=\"myt1\">2. \u7f16\u8bd1\u5b89\u88c5mod_proxy_html\u6a21\u5757<\/div>\n<p>\u6211\u662f\u5728RHEL5.4\u4e0a\u5b89\u88c5\u7684\uff0c\u5e76\u4e0d\u5bb9\u6613\u3002<strong>\u7406\u60f3\u7684\u5b89\u88c5\u6b65\u9aa4<\/strong>\uff08\u4e3a\u4e86\u652f\u6301\u591a\u5b57\u7b26\u96c6\u9700\u8981\u540c\u65f6\u5b89\u88c5mod_xml2enc\uff09\uff1a<\/p>\n<p>1. \u68c0\u67e5\u662f\u5426\u5b89\u88c5\u4e86libxml2\u3002<\/p>\n<p>2. \u4e0b\u8f7dmod_proxy_html\u6e90\u7801\uff1a<a href=\"http:\/\/apache.webthing.com\/mod_proxy_html\/\">\u5730\u5740<\/a>\uff1b\u4e0b\u8f7dmod_xml2enc\u7684\u6e90\u7801\uff1a\u5730\u5740<a href=\"http:\/\/apache.webthing.com\/mod_xml2enc\/\">mod_xml2enc<\/a><\/p>\n<p>3. \u7f16\u8bd1mod_proxy_html\u548cmod_xml2enc\uff1a<\/p>\n<blockquote><p>\nsudo \/usr\/sbin\/apxs -c -I\/usr\/include\/libxml2 -I. -I \/usr\/lib -i mod_proxy_html.c<br \/>\nsudo \/usr\/sbin\/apxs -c -I\/usr\/include\/libxml2 -I. -i mod_xml2enc.c<br \/>\nchmod 755 \/usr\/lib64\/httpd\/modules\/mod_proxy_html.so\n<\/p><\/blockquote>\n<p>\u5982\u679c\u4f60\u8fd9\u4e48\u987a\u5229\u5c31\u7f16\u8bd1\u597d\u4e86\u6a21\u5757\uff0c\u90a3\u4f60\u5f88\u5e78\u8fd0\u3002<\/p>\n<div class=\"myt2\">\u7f16\u8bd1\u4e2d\u7684\u95ee\u9898<\/div>\n<blockquote><p>$ \/usr\/sbin\/apxs -c -I\/usr\/include\/libxml2 -I. -I \/usr\/lib -i mod_proxy_html.c<br \/>\n&#8220;my&#8221; variable $libdir masks earlier declaration in same scope at \/usr\/sbin\/apxs line 36.<br \/>\n\/apr-1\/build\/libtool &#8211;silent &#8211;mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector &#8211;param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I\/usr\/include\/httpd  -I\/usr\/include\/apr-1   -I\/usr\/include\/apr-1  -I\/usr\/include\/libxml2 -I. -I\/usr\/lib  -c -o mod_proxy_html.lo mod_proxy_html.c &#038;&#038; touch mod_proxy_html.slo<br \/>\nsh: \/apr-1\/build\/libtool: No such file or directory<br \/>\napxs:Error: Command failed with rc=8323072<\/p><\/blockquote>\n<p>\u4ed4\u7ec6\u770b\u662f\uff1a<strong>\/apr-1\/build\/libtool: No such file or directory<\/strong>\u3002\u5bf9libtool\u548capr-1\u4e0d\u5f88\u719f\u6089\uff0c\u770b\u51fa\u662f\u56e0\u4e3a\u6ca1\u6709\u6b63\u786e\u627e\u5230libtool\u7684\u8def\u5f84\u5bfc\u81f4\u7684\uff0c\u6240\u4ee5\u4fee\u6539\u4e86\u4e00\u4e0b\u811a\u672capxs\uff0c\u5f3a\u5236\u6307\u5b9alibtool\u7684\u4f4d\u7f6e\uff0c\u867d\u7136\u8fd9\u4e0d\u662f\u201c\u4f18\u96c5\u7684\u201d\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<div class=\"mycode\">\n$locate libtool   #\u627e\u5230\u4f60\u7684libtool<br \/>\n&#8230;&#8230;<br \/>\n$vi \/usr\/sbin\/apxs<br \/>\n&#8230;<br \/>\nmy $libtool = `$apr_config &#8211;apr-libtool`;<br \/>\nchomp($libtool);<br \/>\n$libtool = &#8220;\/usr\/lib64\/apr-1\/build\/libtool&#8221;;<br \/>\n&#8230;\n<\/div>\n<p>It works!  \u5982\u679c\u6709\u4e2a\u6709\u66f4\u597d\u7684\u529e\u6cd5\uff0c\u6216\u8005\u77e5\u9053\u6839\u672c\u539f\u56e0\u7684\uff0c\u8bf7\u544a\u8bc9\u6211\uff0c\u8c22\u8fc7\u5148\u3002<\/p>\n<div class=\"myt1\">3. \u914d\u7f6e\u8be5\u6a21\u5757<\/div>\n<p>\u5f3a\u70c8\u5efa\u8bae\u53c2\u8003mod_proxy_html\u6e90\u7801\u4e2d\u7684proxy_html.conf\uff0c\u8fd9\u662f\u4e00\u4e2a\u793a\u4f8b\u914d\u7f6e\u6587\u4ef6\uff0c\u975e\u5e38\u6709\u6307\u5bfc\u610f\u4e49\u3002\u6211\u8fd9\u91cc\u7684\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<p>1. \u52a0\u8f7d\u5fc5\u8981\u7684\u6a21\u5757\uff1a<\/p>\n<blockquote><p>LoadFile \/usr\/lib64\/libxml2.so<br \/>\nLoadModule xml2enc_module modules\/mod_xml2enc.so<br \/>\nLoadModule proxy_html_module modules\/mod_proxy_html.so<\/p><\/blockquote>\n<p>2. \u6307\u5b9a\u9700\u8981\u4fee\u6539\u7684\u94fe\u63a5\u6807\u7b7e\uff1a<\/p>\n<blockquote><p>SetOutputFilter proxy-html<br \/>\nProxyHTMLExtended On<br \/>\nProxyHTMLLinks  a           href<br \/>\nProxyHTMLLinks  area        href<br \/>\nProxyHTMLLinks  link        href<br \/>\nProxyHTMLLinks  img         src longdesc usemap<br \/>\nProxyHTMLLinks  object      classid codebase data usemap<br \/>\nProxyHTMLLinks  q           cite<br \/>\nProxyHTMLLinks  blockquote  cite<br \/>\nProxyHTMLLinks  ins         cite<br \/>\nProxyHTMLLinks  del         cite<br \/>\nProxyHTMLLinks  form        action<br \/>\nProxyHTMLLinks  input       src usemap<br \/>\nProxyHTMLLinks  head        profile<br \/>\nProxyHTMLLinks  base        href<br \/>\nProxyHTMLLinks  script      src for<br \/>\nProxyHTMLEvents onclick ondblclick onmousedown onmouseup \\<br \/>\n        onmouseover onmousemove onmouseout onkeypress \\<br \/>\n        onkeydown onkeyup onfocus onblur onload \\<br \/>\n        onunload onsubmit onreset onselect onchange<\/p><\/blockquote>\n<p>3. \u6307\u5b9a\u7684URL\u66ff\u6362\u89c4\u5219\uff1a<\/p>\n<pre><blockquote>\r\nProxyPassMatch ^\/proxy_dir\/(.*)$ http:\/\/yourdomain\/$1\r\n&lt;LocationMatch \"\/proxy_dir\/\">\r\n        ProxyPassReverse \/\r\n        ProxyHTMLURLMap  \/ \/proxy_dir\/\r\n        ProxyHTMLURLMap  http:\/\/some_(reg_exp)_url_(is_supported)you_wanna_replace\/  \/proxy_dir\/$1\/$2\/ R\r\n        RequestHeader    unset  Accept-Encoding\r\n&lt;\/LocationMatch><\/blockquote><\/pre>\n<p>OK\uff0cThat&#8217;s all.<\/p>\n<p><script type=\"text\/javascript\" src=\"http:\/\/www.xiami.com\/widget\/player-single?uid=318706&#038;sid=1769953757&#038;mode=js\"><\/script><\/p>\n<p>\u5e7f\u544a\uff1a<a href=\"http:\/\/www.orczhou.com\/index.php\/projects\/we-are-hunting-mysql-hacker\/\">\u6211\u4eec\u5bfb\u627e\u9760\u8c31\u7684\u4eba<\/a> | <a href=\"http:\/\/www.orczhou.com\/index.php\/wish-list\/\">\u611f\u8c22\u4f5c\u8005<\/a><\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<p>1. <a href=\"http:\/\/apache.webthing.com\/mod_proxy_html\/\">mod_proxy_html\u4e3b\u9875<\/a><\/p>\n<p>2. <a href=\"http:\/\/www.apachetutor.org\/admin\/reverseproxies\">Running a Reverse Proxy in Apache<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528\u548c\u914d\u7f6e\u8fc7\u7a0b\u4e2d\uff0c\u8fd8\u662f\u9047\u5230\u4e86\u4e00\u4e9b\u6ce2\u6298\uff0c\u8fd9\u91cc\u5206\u4eab\u3001\u8bb0\u5f55\u4e00\u4e0b\u3002 1. \u6a21\u5757mod_proxy_html\u53ef\u4ee5\u505a\u4e9b\u4ec0\u4e48 \u4f7f\u7528Apache\u5185\u7f6e\u7684mod_proxy\u7684Proxypass\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5b9e\u73b0\u57fa\u672c\u7684\u53cd\u5411\u4ee3\u7406\u529f\u80fd\u3002\u4f46\u662f\uff0c\u4ee3\u7406\u8fd4\u56de\u7684\u7ed3\u679c\u9875\u9762\u5305\u542b\u7684\u94fe\u63a5\u5e76\u4e0d\u4f1a\u88ab\u91cd\u5199\uff0c\u6240\u4ee5\u5982\u679c\u88ab\u4ee3\u7406\u7684Server\u8fd4\u56de\u7684\u662f\u7edd\u5bf9\u5730\u5740\uff0c\u7528\u6237\u5219\u65e0\u6cd5\u6b63\u786e\u8bbf\u95ee\u8fd9\u4e9b\u94fe\u63a5\u3002\u4f8b\u5982\uff1a \u6211\u4eec\u6709\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668http:\/\/myproxy.taobao.org\/\uff0c\u800c\u5185\u7f51\u6709\u9700\u8981\u4ee3\u7406\u7684\u670d\u52a1\u5668http:\/\/internalserver.taobao.org\/\uff0c\u901a\u8fc7\u57fa\u672c\u7684\u53cd\u5411\u4ee3\u7406\u6307\u4ee4Proxypass\uff1a ProxyPass ^\/proxy_internal\/(.*)$ http:\/\/internalserver.taobao.org\/$1 \u53ef\u4ee5\u5b8c\u6210\u57fa\u672c\u7684\u53cd\u5411\u4ee3\u7406\u4efb\u52a1\uff0c\u4f46\u662f\u5982\u679cinternalserver.taobao.org\u8fd4\u56de\u7684HTML\u4ee3\u7801\u4e2d\u6709\u5982\u4e0b\u94fe\u63a5\uff0c\u5219\u5ba2\u6237\u7aef\u5219\u65e0\u6cd5\u6b63\u5e38\u94fe\u63a5\u5230\u76ee\u6807\u9875\u9762\u4e86\uff1a &lt;a href=&#8221;\/test\/index.html&#8221;>Sample Link&lt;\/a> \u56e0\u4e3a\uff0c\u5ba2\u6237\u7aef\u70b9\u51fb\u8be5\u94fe\u63a5\u65f6\u4f1a\u5b9a\u5411\u5230http:\/\/myproxy.taobao.org\/test\/index.html\uff0c\u800c\u8d44\u6e90\u5b9e\u9645\u662f\u5728http:\/\/internalserver.taobao.org\/test\/index.html\u4e0a\u3002 Apache\u81ea\u5e26\u7684mod_proxy\u65e0\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u5f00\u6e90\u7684\u7b2c\u4e09\u65b9\u6a21\u5757mod_proxy_html\u4e3a\u6b64\u800c\u751f\u3002\u7ecf\u8fc7\u4ee3\u7406\u670d\u52a1\u5668\u7684HTML\u53ef\u4ee5\u901a\u8fc7\u8be5\u6a21\u5757\u505a\u4e00\u6b21\u66ff\u6362\uff0c\u4ece\u800c\u53d8\u6210\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\u7684URL\uff08\u4e0a\u4f8b\u4e2d\u4f1a\u628a\/oninternal\/index.html\u66ff\u6362\u6210\/proxy_internal\/test\/index.html\uff09\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[4],"tags":[78,80,79],"class_list":["post-3335","post","type-post","status-publish","format-standard","hentry","category-code-detail","tag-apache","tag-reverse-proxy","tag-79"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/3335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=3335"}],"version-history":[{"count":26,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/3335\/revisions"}],"predecessor-version":[{"id":3361,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/3335\/revisions\/3361"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=3335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=3335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=3335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}