<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>风叶 &#187; 代理</title>
	<atom:link href="http://blog.myhnet.cn/tag/%e4%bb%a3%e7%90%86/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.myhnet.cn</link>
	<description>秋湍泻石髓 风叶聚云根</description>
	<lastBuildDate>Wed, 28 Jul 2010 16:00:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>利用apache的proxy来做负载均衡</title>
		<link>http://blog.myhnet.cn/2009/11/09/make-load-balance-rules-with-mod_proxy-in-apache/</link>
		<comments>http://blog.myhnet.cn/2009/11/09/make-load-balance-rules-with-mod_proxy-in-apache/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 11:11:41 +0000</pubDate>
		<dc:creator>myhnet</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[负载均衡]]></category>
		<category><![CDATA[load balance]]></category>
		<category><![CDATA[mod_proxy]]></category>
		<category><![CDATA[mod_proxy_balancer]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[代理]]></category>
		<category><![CDATA[代理负载均衡]]></category>

		<guid isPermaLink="false">http://blog.myhnet.cn/?p=873</guid>
		<description><![CDATA[虽然很早以前就知道得用apche的mod_proxy可以用来做负载均衡，可由于太懒，一直都没有去做。今天刚好工作上也要做这个，所以就实验了一把。 要使用apache的负载均衡功能，首得得开启下面这几个模块： LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_balancer_module modules/mod_proxy_balancer.soLoadModule proxy_http_module modules/mod_proxy_http.so 其中mod_proxy提供代理服务器功能，mod_proxy_balancer提供负载均衡功能， mod_proxy_http让代理服务器能支持HTTP协议。 然后，要在httpd.conf中加入这么一段配置： ProxyRequests Off&#60;Proxy balancer://mycluster&#62;&#160;&#160; &#160;BalancerMember http://192.168.0.1&#160;&#160; &#160;BalancerMember http://192.168.0.2&#60;/Proxy&#62;ProxyPass /mycluster !ProxyPass / balancer://mycluster&#60;Location /mycluster&#62;&#160;&#160; &#160;SetHandler balancer-manager&#160;&#160; &#160;Order Deny,Allow&#160;&#160; &#160;Deny from all&#160;&#160; &#160;Allow from localhost&#60;/Location&#62; 从上面的 ProxyRequests Off 这条可以看出，实际上负载均衡器就是一个反向代理， 只不过它的代理转发地址不是某台具体的服务器，而是一个 balancer:// 协议： ProxyPass / balancer://mycluster 下面那段是用来监视负载均衡的工作情况的，然后访问 http://localhost/mycluster/ 即可看到负载均衡的工作状况。你也可以利用这个工具将其中某一个终端要暂时从集群中移出，或者临时修改某个终端的参数（如factor等）。 这个地方要特别注意的是下面这行配置： ProxyPass /mycluster ! 如果没有这行配置，当你访问http://localhost/mycluster/也会被转发到终端上去。 改完之后重启服务器，访问你的Apache所在服务器的地址，即可看到负载均衡的效果了。 打开 mycluster的界面，可以看到请求是平均分配的。 [...]]]></description>
			<content:encoded><![CDATA[<p>虽然很早以前就知道得用apche的mod_proxy可以用来做负载均衡，可由于太懒，一直都没有去做。今天刚好工作上也要做这个，所以就实验了一把。</p>
<p>要使用apache的负载均衡功能，首得得开启下面这几个模块：</p>
<div class="hl-surround"><div class="hl-main">LoadModule proxy_module modules/mod_proxy.so<br />LoadModule proxy_balancer_module modules/mod_proxy_balancer.so<br />LoadModule proxy_http_module modules/mod_proxy_http.so</div></div>
<p>其中mod_proxy提供代理服务器功能，mod_proxy_balancer提供负载均衡功能， mod_proxy_http让代理服务器能支持HTTP协议。</p>
<p>然后，要在httpd.conf中加入这么一段配置：</p>
<div class="hl-surround"><div class="hl-main">ProxyRequests Off<br />&lt;Proxy balancer://mycluster&gt;<br />&nbsp;&nbsp; &nbsp;BalancerMember http://192.168.0.1<br />&nbsp;&nbsp; &nbsp;BalancerMember http://192.168.0.2<br />&lt;/Proxy&gt;<br />ProxyPass /mycluster !<br />ProxyPass / balancer://mycluster<br />&lt;Location /mycluster&gt;<br />&nbsp;&nbsp; &nbsp;SetHandler balancer-manager<br />&nbsp;&nbsp; &nbsp;Order Deny,Allow<br />&nbsp;&nbsp; &nbsp;Deny from all<br />&nbsp;&nbsp; &nbsp;Allow from localhost<br />&lt;/Location&gt;</div></div>
<p>从上面的 ProxyRequests Off 这条可以看出，实际上负载均衡器就是一个反向代理， 只不过它的代理转发地址不是某台具体的服务器，而是一个 balancer:// 协议：</p>
<div class="hl-surround"><div class="hl-main">ProxyPass / balancer://mycluster</div></div>
<p>下面那段<Location /mycluster>是用来监视负载均衡的工作情况的，然后访问 http://localhost/mycluster/ 即可看到负载均衡的工作状况。你也可以利用这个工具将其中某一个终端要暂时从集群中移出，或者临时修改某个终端的参数（如factor等）。</p>
<p>这个地方要特别注意的是下面这行配置：</p>
<div class="hl-surround"><div class="hl-main">ProxyPass /mycluster !</div></div>
<p>如果没有这行配置，当你访问http://localhost/mycluster/也会被转发到终端上去。</p>
<p>改完之后重启服务器，访问你的Apache所在服务器的地址，即可看到负载均衡的效果了。 打开 mycluster的界面，可以看到请求是平均分配的。</p>
<p>当然，你也可以像我这个配置这样修改其中的某些参数，来获得最大的负载均衡的功效</p>
<div class="hl-surround"><div class="hl-main">ProxyRequests Off<br />ProxyPass /mycluster !<br />ProxyPass / balancer://mycluster/ stickysession=BALANCEID<br />ProxyPassReverse / http://192.168.0.1/<br />ProxyPassReverse / http://192.168.0.2/<br />&lt;Proxy balancer://mycluster&gt;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BalancerMember http://192.168.0.1 route=http1 loadfactor=7<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BalancerMember http://192.168.0.2 route=http2 loadfactor=3<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ProxySet lbmethod=byrequests<br />&lt;/Proxy&gt;<br />&lt;Location /mycluster&gt;<br />&nbsp;&nbsp; &nbsp;SetHandler balancer-manager<br />&nbsp;&nbsp; &nbsp;Order Deny,Allow<br />&nbsp;&nbsp; &nbsp;Deny from all<br />&nbsp;&nbsp; &nbsp;Allow from localhost<br />&lt;/Location&gt;</div></div>
<p>其中，stickysession=BALANCEID设置根据下面的route=http1/2来进行session的绑定。因为很多网站的变量，如登陆信息等，可能是储存在服务器端的内存中的，如果不设置这个变量，用户来访问是还是不段的在不同的终端之间切换，用户就会不停的退出<br />
loadfactor=7这个是设置不同的终端的负载均衡的权重，数值越来，转发的数量就越多。<br />
而ProxySet lbmethod=byrequests是用来设置负载均衡的算法。通常有三种取值：byrequests（按照请求次数均衡，默认值），bytraffic（按照流量均衡），bybusyness（按照繁忙程度均衡）。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myhnet.cn/2009/11/09/make-load-balance-rules-with-mod_proxy-in-apache/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>为phpwind做代理加速镜像</title>
		<link>http://blog.myhnet.cn/2009/03/06/make-a-reverse-proxy-mirror-for-phpwind/</link>
		<comments>http://blog.myhnet.cn/2009/03/06/make-a-reverse-proxy-mirror-for-phpwind/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 09:02:05 +0000</pubDate>
		<dc:creator>myhnet</dc:creator>
				<category><![CDATA[PHP & PW]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[base]]></category>
		<category><![CDATA[网站加速]]></category>
		<category><![CDATA[镜像]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[mirror]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpwind]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[代理]]></category>

		<guid isPermaLink="false">http://blog.myhnet.cn/?p=706</guid>
		<description><![CDATA[今天给风云墙做了一个教育网的代理服务器来给教育网的用户加速。本来以为是一个很简单的问题，结果却大费周折。 第一打算是用squid来做，结果却由于原来的80端口被占用，暂时找不到一个圆满的解决方案，只好放弃。 80端口已经被apache占用了，也就只好用mod_proxy来做了。 在apache中加上这么一个vhost，理论上应该是可以了，但是，里面的链接还是指向原来的http://bbs.clwind.net，并不像反向代理所期待的http://edu.clwind.net. &#60;VirtualHost *:80&#62;&#160;&#160; &#160;ServerAdmin myhnet@gmail.com&#160;&#160; &#160;DocumentRoot /none&#160;&#160; &#160;ServerName&#160; edu.clwind.net&#160;&#160; &#160;ProxyRequests Off&#160;&#160; &#160;ProxyPass&#160; / http://bbs.clwind.net&#160;&#160; &#160;ProxyPassReverse / http://bbs.clwind.net&#60;/VirtualHost&#62; 开始一直以为是反向代理的问题（我对反向代理不太熟悉），查找了好久，也没发现问题所在（本来就不是他的问题，怎么可能发现得了）。最好做了一个最简单的网站来做源站，才发现原来是phpwind的head部分的问题。 在phpwind的header.html中，给页面加上了一个base标签 &#60;base id=&#34;headbase&#34; href=&#34;$db_bbsurl/&#34; /&#62; base标签的作用是给网页中的链接指定一个默认的URL前缀或者是指定一个target，比如： &#60;base target=&#34;_blank&#34; /&#62; 而在phpwind中，$db_bbsurl这个变量是由PHP系统变量$_SERVER[HTTP_HOST]得来的。 但是这个变量在使用了反向代理之后，并不是我们访问的URL，这个时候介入了一个新的变量，只有在使用代理访问之后才会有的变量：$_SERVER[HTTP_X_FORWARDED_HOST]。这个变量才是我们访问的URL。 这样，为了反向代理能够正常使用，我们需要更改phpwind的代码。 打开global.php 解决base标签的问题 找到： $R_url = $db_bbsurl = Char_cv(&#34;http://$_SERVER[HTTP_HOST]&#34;.substr($tmp,0,strrpos($tmp,'/'))); 修改为： if ($_SERVER[HTTP_X_FORWARDED_HOST]) {&#160;&#160; &#160; &#160; &#160;$R_url = $db_bbsurl = Char_cv(&#34;http://$_SERVER[HTTP_X_FORWARDED_HOST]&#34;.substr($tmp,0,strrpos($tmp,'/')));} else {&#160;&#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>今天给<a href="http://bbs.clwind.net">风云墙</a>做了一个<a href="http://edu.clwind.net">教育网的代理服务器</a>来给教育网的用户加速。本来以为是一个很简单的问题，结果却大费周折。</p>
<p>第一打算是用squid来做，结果却由于原来的80端口被占用，暂时找不到一个圆满的解决方案，只好放弃。</p>
<p>80端口已经被apache占用了，也就只好用mod_proxy来做了。<br />
在apache中加上这么一个vhost，理论上应该是可以了，但是，里面的链接还是指向原来的http://bbs.clwind.net，并不像反向代理所期待的http://edu.clwind.net.</p>
<div class="hl-surround"><div class="hl-main">&lt;VirtualHost *:80&gt;<br />&nbsp;&nbsp; &nbsp;ServerAdmin myhnet@gmail.com<br />&nbsp;&nbsp; &nbsp;DocumentRoot /none<br />&nbsp;&nbsp; &nbsp;ServerName&nbsp; edu.clwind.net<br />&nbsp;&nbsp; &nbsp;ProxyRequests Off<br />&nbsp;&nbsp; &nbsp;ProxyPass&nbsp; / http://bbs.clwind.net<br />&nbsp;&nbsp; &nbsp;ProxyPassReverse / http://bbs.clwind.net<br />&lt;/VirtualHost&gt;</div></div>
<p>开始一直以为是反向代理的问题（我对反向代理不太熟悉），查找了好久，也没发现问题所在（本来就不是他的问题，怎么可能发现得了）。最好做了一个最简单的网站来做源站，才发现原来是phpwind的head部分的问题。</p>
<p>在phpwind的header.html中，给页面加上了一个base标签</p>
<div class="hl-surround"><div class="hl-main">&lt;base id=&quot;headbase&quot; href=&quot;$db_bbsurl/&quot; /&gt;</div></div>
<p>base标签的作用是给网页中的链接指定一个默认的URL前缀或者是指定一个target，比如：</p>
<div class="hl-surround"><div class="hl-main">&lt;base target=&quot;_blank&quot; /&gt;</div></div>
<p>而在phpwind中，<i>$db_bbsurl</i>这个变量是由PHP系统变量<i>$_SERVER[HTTP_HOST]</i>得来的。</p>
<p>但是这个变量在使用了反向代理之后，并不是我们访问的URL，这个时候介入了一个新的变量，只有在使用代理访问之后才会有的变量：<i>$_SERVER[HTTP_X_FORWARDED_HOST]</i>。这个变量才是我们访问的URL。</p>
<p>这样，为了反向代理能够正常使用，我们需要更改phpwind的代码。<br />
打开<i>global.php</i></p>
<p><b>解决base标签的问题</b><br />
找到：</p>
<div class="hl-surround"><div class="hl-main">$R_url = $db_bbsurl = Char_cv(&quot;http://$_SERVER[HTTP_HOST]&quot;.substr($tmp,0,strrpos($tmp,'/')));</div></div>
<p>修改为：</p>
<div class="hl-surround"><div class="hl-main">if ($_SERVER[HTTP_X_FORWARDED_HOST]) {<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;$R_url = $db_bbsurl = Char_cv(&quot;http://$_SERVER[HTTP_X_FORWARDED_HOST]&quot;.substr($tmp,0,strrpos($tmp,'/')));<br />} else {<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;$R_url = $db_bbsurl = Char_cv(&quot;http://$_SERVER[HTTP_HOST]&quot;.substr($tmp,0,strrpos($tmp,'/')));<br />}</div></div>
<p><b>解决前台发帖的非法操作问题</b><br />
同样在<i>global.php</i>中：<br />
找到：</p>
<div class="hl-surround"><div class="hl-main">list($http_host) = explode(':',$_SERVER['HTTP_HOST']);</div></div>
<p>修改为：</p>
<div class="hl-surround"><div class="hl-main">if ($_SERVER[HTTP_X_FORWARDED_HOST]){<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;list($http_host) = explode(':',$_SERVER['HTTP_X_FORWARDED_HOST']);<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;list($http_host) = explode(':',$_SERVER['HTTP_HOST']);<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div></div>
<p><b>解决多重代理IP unknow问题</b><br />
还是<i>global.php</i><br />
找到：</p>
<div class="hl-surround"><div class="hl-main">$onlineip = $_SERVER['HTTP_X_FORWARDED_FOR'];</div></div>
<p>改为：</p>
<div class="hl-surround"><div class="hl-main">$ip_temp=explode(&quot;,&quot;,$_SERVER['HTTP_X_FORWARDED_FOR']);<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;$onlineip = $ip_temp[0];</div></div>
<p>这样子做有一个BUG：如果访问者用内网代理，得到的IP将会是内网IP。我正在想办法解决。</p>
<p>最后，要做的就是解决后台操作非法的问题。由于有我前面说的那个BUG，我不建议修改这个，可以说明的就是修改的方法跟前台类似。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myhnet.cn/2009/03/06/make-a-reverse-proxy-mirror-for-phpwind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
