<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[[Nginx实战]Nginx实现负载均衡的服务器集群配置及用PHP结合Smarty去自动化配置Nginx的负载均衡文件实现自动化的可行性备案。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Tue, 06 Mar 2012 08:15:19 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	代理的项目示例：<br/><textarea name="code" class="php" rows="15" cols="100">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;location /justwinit/ &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_redirect off ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header Host jackxiang.com;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header X-Real-IP $remote_addr;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass http://127.0.0.1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
</textarea><br/>1)Apache 开80端口，Htdocs：D:&#92;apmxe&#92;htdocs&#92;index.html<br/>2）Nginx配置两样东西。<br/>&nbsp;&nbsp;&nbsp;&nbsp;（1）8080端口是用来当成负载均衡的一台机器。<br/>&nbsp;&nbsp;&nbsp;&nbsp;（2）72端口是入口，用来做入口，72下面是变的多台机器的端口来做负载均衡。<br/>Nginx的配置文件如下，加入了对目录的浏览：<br/><textarea name="code" class="html" rows="15" cols="100">
&nbsp;&nbsp;server &#123;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;listen 72;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;server_name localhost;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;location / &#123;&nbsp;&nbsp;
&nbsp;&nbsp;proxy_next_upstream http_502 http_504 error timeout invalid_header http_500 http_503 http_404 ;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass http://myproject;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header Host&nbsp;&nbsp;www.jackxiang.com; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header X-Forwarded-For&nbsp;&nbsp;$remote_addr; 
&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp;
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;server &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8080;
&nbsp;&nbsp;autoindex on;
&nbsp;&nbsp;autoindex_exact_size off;
&nbsp;&nbsp;autoindex_localtime on;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server_name&nbsp;&nbsp;localhost;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;location / &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root&nbsp;&nbsp; html;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;&nbsp;index.html index.htm index.php;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error_page&nbsp;&nbsp; 500 502 503 504&nbsp;&nbsp;/50x.html;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
</textarea><br/>访问：http://localhost:72/index.html <br/>测试：把Nginx里的htdocs文件index.html去掉后，一直能访问到，因为nginx这个负载均衡的proxy_next_upstream参数就是干这个事情的，于是否，我们发现一直能访问，<br/>但如果只访问：http://localhost:72 出现当访问到Nginx那一台出现因访问到目录的情况，是因为上面的命令打开了目录浏览，认为有数据返回，不是：http_502 http_504 error timeout invalid_header http_500 http_503 http_404，所以没有转移走，于是否，出现了目录的情况。<br/>=============================================================================<br/>可能出现的问题：[emerg]: &quot;upstream&quot; directive is not allowed here in ......<br/>后来检查了一下原来是upstream backend 位置放错了, upstream位置应该放在http模块里面 但必须是在server模块的外面. <br/>参考：http://wiki.nginx.org/LoadBalanceExample<br/><br/>再就是这种多IP下的Nginx负载均衡怎么用PHP的Smarty来自动化呢？一般情况都如下：<br/><textarea name="code" class="php" rows="15" cols="100">
upstream bbs_server_pool &#123;

&nbsp;&nbsp; server&nbsp;&nbsp; 192.168.1.24:80 weight=1 max_fails=2 fail_timeout=30s;

&nbsp;&nbsp; server&nbsp;&nbsp; 192.168.1.25:80 weight=2 max_fails=2 fail_timeout=30s;

&nbsp;&nbsp; server&nbsp;&nbsp; 192.168.1.26:80 weight=10 max_fails=2 fail_timeout=30s;

 &#125;
</textarea><br/>PHP的Smarty去配置server实现思考:<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;&#123;foreach from=$sourceurl key=k item=v&#125;&gt;
&nbsp;&nbsp; server &lt;&#123;$v&#125;&gt; weight=1 max_fails fail_timeout=30s;
&lt;&#123;/foreach&#125;&gt;
localip = &lt;&#123;$ip&#125;&gt;
</textarea><br/><br/>经PHP的smarty翻译后如下：<br/>server 1.1 weight=1 max_fails fail_timeout=30s;<br/>server 1.2 weight=1 max_fails fail_timeout=30s;<br/>localip = 72.46.128.82<br/><br/>这样，也就实现了Nginx的自动配置，做一个前端的Web界面，后经过zoomkeeper，进行自动重启动nginx，进而reload这个修改过的nginx的配置文件即可。
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [Nginx实战]Nginx实现负载均衡的服务器集群配置及用PHP结合Smarty去自动化配置Nginx的负载均衡文件实现自动化的可行性备案。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>