<?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>apt-blog.net   无证程序员的PT桑 &#187; Unix/Linux</title>
	<atom:link href="http://apt-blog.net/category/tech/unix_linux/feed" rel="self" type="application/rss+xml" />
	<link>http://apt-blog.net</link>
	<description>潜逃中。</description>
	<lastBuildDate>Fri, 18 May 2012 11:25:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>An OpenVPN configuration menu based generator</title>
		<link>http://apt-blog.net/an-openvpn-configuration-menu-based-generator</link>
		<comments>http://apt-blog.net/an-openvpn-configuration-menu-based-generator#comments</comments>
		<pubDate>Fri, 18 May 2012 11:10:26 +0000</pubDate>
		<dc:creator>BOYPT</dc:creator>
				<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[openvpn]]></category>
		<guid isPermaLink="false">https://apt-blog.net/?p=1228</guid>
		<description><![CDATA[Setting up an openvpn server isn't a diffcult thing, but you have to deal with root certificates, rsa keys, confs, subnet addresses, iptables ... such trifles are annoying. So I wrote this script to make my life easier, only to provide basic infomation like the server IP, and those configuraion will be done at the [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up an openvpn server isn't a diffcult thing, but you have to deal with root certificates, rsa keys, confs, subnet addresses, iptables ... such trifles are annoying.</p>
<p>So I wrote this script to make my life easier, only to provide basic infomation like the server IP, and those configuraion will be done at the background, then tared packages are ready there for both server and clients.</p>
<p><a href="http://apt-blog.net/wp-content/uploads/2012/05/ovpn_menu.png" rel="lightbox[1228]" title="ovpn_menu.png"><img title="ovpn_menu.png" alt="ovpn_menu.png" src="http://apt-blog.net/wp-content/uploads/2012/05/ovpn_menu.png" class="aligncenter" width="65%" /></a></p>
<p>Source is available at <a href="http://code.google.com/p/ptcoding/source/browse/ovpn_menu.sh">Google Code</a>.</p>
<p><strong>Script is recommanded running at your work station, and then upload only the server part tared file to the server, for secure concideration.</strong></p>
<h3>Features</h3>
<ul>
<li>Provide tared config which ready for any server distribution.</li>
<li>Random VPN subnet will be generated to avoid conflicting.</li>
<li>Random digital subffixed server/client CommonName will be assigned (if you don't provide one) for clearer management.</li>
<li>Configuration file is copied from the distributed OpenVPN in your system, which include full explnations of different options when you have to edit them. Default values is set by sed.</li>
<li>tls-auth enabled by default. </li>
</ul>
<h3>Usage</h3>
<p>For new setup:</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>ovpn_menu.sh</pre></td></tr></table></div>
</p>
<p>Just do as promoted. When select 5 to exit, all the files will be packed into a single <code>NAME-all.tar.gz</code>, you should save it to somewhere safe. And if you want to sign some more certificate from this root ca, put this tar file as the argument.</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>ovpn_menu.sh <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>YOUR-VPN-all.tar.gz</pre></td></tr></table></div>
<p>At last the script also provide you iptables commands that should be useful to setup the server.</p>
<h3>Download</h3>
<p>Direct download via wget/curl should be ok:</p>
<p><a href="http://ptcoding.googlecode.com/git/ovpn_menu.sh">http://ptcoding.googlecode.com/git/ovpn_menu.sh</a></p>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/an-openvpn-configuration-menu-based-generator/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一次本博客的性能故障排查</title>
		<link>http://apt-blog.net/trace_on_a_performace_problem</link>
		<comments>http://apt-blog.net/trace_on_a_performace_problem#comments</comments>
		<pubDate>Sat, 31 Mar 2012 07:02:53 +0000</pubDate>
		<dc:creator>BOYPT</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[运维技术]]></category>
		<guid isPermaLink="false">https://apt-blog.net/?p=1163</guid>
		<description><![CDATA[无关背景 Ubuntu 10.04 这个版本已经服役两年，虽说是LTS，但最近起发现已经有点力不从心，主要是ppa上一些比较重要的库，如PHP 5.3，ningx的团队已经停止维护，uwsgi则总是落后半年的样子。很大一个原因是这些包在新版的Ubuntu里面已经有官方维护，ppa的第三方维护会缺乏跟进。所以在一定意义上，可以宣布Ubuntu 10.04死亡了。 但Ubuntu的包维护策略就是那样，要么自己维护所有用到的包，要么每隔一段时间就跟着官方一次大升级。觉得不爽就干脆把VPS的系统也改成Archlinux。 现象 一番大迁移后所有的东西都正常上线，但直到一个多星期后的昨天晚上才注意到博客的性能问题。 因为博客那里有nginx直接读取静态的缓冲机制，所以动态执行非常慢之前都没留意到。 把缓冲关闭就非常明显了，任何一次点击的页面都要10秒才能打开。 排查 引起应用缓慢的因素是非常多的，概括来说有两种：IO慢、运算慢。 运算慢是不大常见的，虽说PHP性能一直受到诟病。但如果是这个问题是很明显的，top里面php的子进程会占满CPU，高居不下。此前排查过一个drupal的站点，是因为前端模板的组件方式存在循环引用，用profile过程看，正则替换的regrex函数占了绝大多的CPU时间。 在SSH看到，打开页面的10秒内php-fpm的子进程基本没占CPU，排除这个可能。 IO慢就复杂了，每个组件都有IO，得先确定IO的范围。 首先想到是数据库Mysql，arch的包太新，有bug？linode主机的磁盘快挂了，磁盘很慢？这些都不好判断，确定这些得借助工具。 Profiling是追踪一个应用的运行流程，记录所有的函数调用栈、记录调用时间的过程，是追查性能问题的最佳帮手。Python里面是有个repoze.profile的wsgi中间件很方便进行排查，但我没做过完整PHP开发，就暂时不大清楚有什么方便的profile方案 （以前弄过早忘了），但google一下还是有很多方案的 ，不过我首先想起newrelic的应用监控系统就提供了这个功能。 Newrelic针对WEB应用和服务器监控服务，其中的服务器监控是免费的，但对应用的监控只有14天试用；所以我赶紧重新申请个帐号，用来监控一下wordpress。安装好监控模块后，超过2s的响应会在他们的Transaction traces记录下来。 图表数据可以排除数据库问题，几十个数据库的操作都是在ms级别完成，而在apt-blog.net的耗时花了10秒。其实我一开始对这个报告也没看懂，newrelic的直观性还有待提高，其实在这里出现域名的意思是有网络请求，比如askimet的评论、插件的更新等都要和外部请求，这里就会出现域名。 而现在出现了自己博客的域名，那问题就是，程序里面某个地方需要请求自己的域名，可能是检查状态的操作，被卡住了，直到超时才返回。 本机程序访问不到本机，基本确定是iptables规则出问题了，在filter表的最后插入这样一句： -A INPUT -j LOG iptables的规则一般是，除非明文允许，否则拒绝，所以经过一系列的规则后如果还没有没ACCEPT的，在最后的都是被DROP了，把这句放最后可以看到究竟是什么包被DROP了。 查看/var/log/everything.log看到这样的记录： Mar 31 03:17:32 (none) kernel: [17554800.765033] IN=lo OUT= MAC=00:00:00:00:00:0 0:00:00:00:00:00:00:08:00 SRC=106.187.36.50 DST=106.187.36.50 LEN=60 TOS=0x00 PR EC=0x00 TTL=64 ID=31529 DF PROTO=TCP SPT=45594 DPT=80 WINDOW=32792 RES=0x00 [...]]]></description>
			<content:encoded><![CDATA[<h2>无关背景</h2>
<p>Ubuntu 10.04 这个版本已经服役两年，虽说是LTS，但最近起发现已经有点力不从心，主要是ppa上一些比较重要的库，如PHP 5.3，ningx的团队已经停止维护，uwsgi则总是落后半年的样子。很大一个原因是这些包在新版的Ubuntu里面已经有官方维护，ppa的第三方维护会缺乏跟进。所以在一定意义上，可以宣布Ubuntu 10.04死亡了。</p>
<p>但Ubuntu的包维护策略就是那样，要么自己维护所有用到的包，要么每隔一段时间就跟着官方一次大升级。觉得不爽就干脆把VPS的系统也改成Archlinux。</p>
<h2>现象</h2>
<p>一番大迁移后所有的东西都正常上线，但直到一个多星期后的昨天晚上才注意到博客的性能问题。 因为博客那里有nginx直接读取静态的缓冲机制，所以动态执行非常慢之前都没留意到。</p>
<p>把缓冲关闭就非常明显了，任何一次点击的页面都要10秒才能打开。</p>
<h2>排查</h2>
<p>引起应用缓慢的因素是非常多的，概括来说有两种：<strong>IO慢</strong>、<strong>运算慢</strong>。</p>
<p>运算慢是不大常见的，虽说PHP性能一直受到诟病。但如果是这个问题是很明显的，<code>top</code>里面php的子进程会占满CPU，高居不下。此前排查过一个drupal的站点，是因为前端模板的组件方式存在循环引用，用profile过程看，正则替换的regrex函数占了绝大多的CPU时间。</p>
<p>在SSH看到，打开页面的10秒内php-fpm的子进程基本没占CPU，排除这个可能。</p>
<p>IO慢就复杂了，每个组件都有IO，得先确定IO的范围。</p>
<p>首先想到是数据库Mysql，arch的包太新，有bug？linode主机的磁盘快挂了，磁盘很慢？这些都不好判断，确定这些得借助工具。</p>
<p>Profiling是追踪一个应用的运行流程，记录所有的函数调用栈、记录调用时间的过程，是追查性能问题的最佳帮手。Python里面是有个<a href="http://docs.repoze.org/profile/">repoze.profile</a>的wsgi中间件很方便进行排查，但我没做过完整PHP开发，就暂时不大清楚有什么方便的profile方案 （以前弄过早忘了），但<a href="https://www.google.com/search?q=PHP+profiling">google一下还是有很多方案的</a> ，不过我首先想起<code>newrelic</code>的应用监控系统就提供了这个功能。</p>
<p><a href="https://newrelic.com/">Newrelic</a>针对WEB应用和服务器监控服务，其中的服务器监控是免费的，但对应用的监控只有14天试用；所以我赶紧重新申请个帐号，用来监控一下wordpress。安装好监控模块后，超过2s的响应会在他们的<code>Transaction traces</code>记录下来。</p>
<p><a href="http://apt-blog.net/wp-content/uploads/2012/03/newrelic-profile-apt-blog.png" rel="lightbox[1163]" title="newrelic-profile-apt-blog.png"><img title="newrelic-profile-apt-blog.png" alt="newrelic-profile-apt-blog.png" src="http://apt-blog.net/wp-content/uploads/2012/03/newrelic-profile-apt-blog.png" class="aligncenter" width="80%" /></a></p>
<p>图表数据可以排除数据库问题，几十个数据库的操作都是在ms级别完成，而在<code>apt-blog.net</code>的耗时花了10秒。其实我一开始对这个报告也没看懂，newrelic的直观性还有待提高，其实在这里出现域名的意思是有网络请求，比如askimet的评论、插件的更新等都要和外部请求，这里就会出现域名。</p>
<p>而现在出现了自己博客的域名，那问题就是，程序里面某个地方需要请求自己的域名，可能是检查状态的操作，被卡住了，直到超时才返回。</p>
<p>本机程序访问不到本机，基本确定是iptables规则出问题了，在filter表的<strong>最后</strong>插入这样一句：</p>
<pre><code>-A INPUT -j LOG
</code></pre>
<p>iptables的规则一般是，<strong>除非明文允许，否则拒绝</strong>，所以经过一系列的规则后如果还没有没ACCEPT的，在最后的都是被DROP了，把这句放最后可以看到究竟是什么包被DROP了。</p>
<p>查看<code>/var/log/everything.log</code>看到这样的记录：</p>
<pre><code>Mar 31 03:17:32 (none) kernel: [17554800.765033] IN=lo OUT= MAC=00:00:00:00:00:0 0:00:00:00:00:00:00:08:00 SRC=106.187.36.50 DST=106.187.36.50 LEN=60 TOS=0x00 PR EC=0x00 TTL=64 ID=31529 DF PROTO=TCP SPT=45594 DPT=80 WINDOW=32792 RES=0x00 SYN URGP=0
</code></pre>
<p>这里透露了重要信息：<code>IN=lo SRC=106.187.36.50 DST=106.187.36.50</code>，PHP确实有访问本地网络，送了给lo网卡，SRC和DST都是本地的公网地址。赶紧检查iptables的规则，果然没了对lo设备的允许规则。一般配置机器我都是用记录在<a href="http://wiki.ptsang.net/Iptables配置">自己的Wiki的iptables那套规则</a>的。关于lo的这几句可能一时没仔细想其作用，迁移系统那天脑抽手贱就删掉了。</p>
<p>加入允许lo设备的这句：</p>
<pre><code>-A INPUT -i lo -j ACCEPT
</code></pre>
<p>至此，问题解决。</p>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/trace_on_a_performace_problem/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenVPN over HTTP 突破Layer 7 QoS的宽带网速限制</title>
		<link>http://apt-blog.net/break-through-l7qos-with-openvpn-over-http</link>
		<comments>http://apt-blog.net/break-through-l7qos-with-openvpn-over-http#comments</comments>
		<pubDate>Sun, 04 Mar 2012 11:26:28 +0000</pubDate>
		<dc:creator>BOYPT</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[openvpn]]></category>
		<category><![CDATA[polipo]]></category>
		<category><![CDATA[proxy]]></category>
		<guid isPermaLink="false">https://apt-blog.net/?p=1156</guid>
		<description><![CDATA[Why 我家里用的是一家三线的便宜小区宽带，标称有几个M的带宽，虽说有些资源确实能达到这个速度，但发现直连VPN的速度从来都没上去过，大概30k/s，不难猜测到，ISP在链路上做了手脚，即所谓的Layer 7 Priority QoS。因为入线是100M进宅然后PPPoE，不像ADSL那样直接物理链路就限制了连接速度，在链路层做QoS也很合理。平时HTTP打开网页、下载到合适链路的话很容易达到满速，而OpenVPN的TCP/UDP包估计就被当成P2P流量被限制了，所以网速一点都不给力。 用OpenVPN科学上网是最稳定最灵活的方式了，它基于udp/tcp的协议，比pptp、l2tp等直接跑IP包的开销虽说大一点，但好处就是容易把数据流重新封装，避开链路的关卡。显然它也支持HTTP代理，所以把OpenVPN变成HTTP协议，就可以在家里跑上满速的VPN。 How OpenVPN要过HTTP代理，只能用TCP协议，这个需要服务端和客户端都要稍作修改。 Polipo as Tunnel Proxy 首先在VPS上安装一个http proxy，我选择polipo，比较轻量级。 apt-get install polipo 配置也是很简单的，编辑/etc/polipo/config，原来的配置文件基本全都是注释，直接在文件底部加上： proxyAddress = &#34;0.0.0.0&#34; proxyPort = 8128 authCredentials = &#34;user:password3.141592654&#34; tunnelAllowedPorts = 1194 polipo默认只监听本地的127.0.0.1，要拿来做服务就要监听外网 polipo默认监听8123，为了不让扫代理的盯上，自己随便写个端口 加上http basic验证，这个密码不要紧，后面让openvpn自动应答 允许管道模式连接openvpn的1194端口 OpenVPN Server 服务端倒是不需要很多配置，确定是tcp模式监听连接（我是多开一个openvpn server，子网错开，个人喜欢吧） Client 客户端就要指定使用代理的方式： remote 127.0.0.1 1194 http-proxy YOUR.VPS.IP.HERE.com 8128 pw.txt http-proxy-retry 这个pw.txt是上述的HTTP的认证信息，用户名密码各一行。 现在连接OpenVPN，可以看到连接过程的Log有这么几句，基本就确定OpenVPN over HTTP成功了！ Sun Mar [...]]]></description>
			<content:encoded><![CDATA[<h1>Why</h1>
<p>我家里用的是一家三线的便宜小区宽带，标称有几个M的带宽，虽说有些资源确实能达到这个速度，但发现直连VPN的速度从来都没上去过，大概30k/s，不难猜测到，ISP在链路上做了手脚，即所谓的Layer 7 Priority QoS。因为入线是100M进宅然后PPPoE，不像ADSL那样直接物理链路就限制了连接速度，在链路层做QoS也很合理。平时HTTP打开网页、下载到合适链路的话很容易达到满速，而OpenVPN的TCP/UDP包估计就被当成P2P流量被限制了，所以网速一点都不给力。</p>
<p>用OpenVPN<strong><a href="https://www.google.com/search?ie=UTF-8&amp;q=%E7%A7%91%E5%AD%A6%E4%B8%8A%E7%BD%91">科学上网</a></strong>是最稳定最灵活的方式了，它基于udp/tcp的协议，比pptp、l2tp等直接跑IP包的开销虽说大一点，但好处就是容易把数据流重新封装，避开链路的关卡。显然它也支持HTTP代理，所以把OpenVPN变成HTTP协议，就可以在家里跑上满速的VPN。</p>
<h1>How</h1>
<p>OpenVPN要过HTTP代理，只能用TCP协议，这个需要服务端和客户端都要稍作修改。</p>
<h3>Polipo as Tunnel Proxy</h3>
<p>首先在VPS上安装一个http proxy，我选择polipo，比较轻量级。</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> polipo</pre></div></div>
<p>配置也是很简单的，编辑<code>/etc/polipo/config</code>，原来的配置文件基本全都是注释，直接在文件底部加上：</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">proxyAddress = &quot;0.0.0.0&quot;
proxyPort = 8128
authCredentials = &quot;user:password3.141592654&quot;
tunnelAllowedPorts = 1194</pre></div></div>
<ul>
<li>polipo默认只监听本地的127.0.0.1，要拿来做服务就要监听外网</li>
<li>polipo默认监听8123，为了不让扫代理的盯上，自己随便写个端口</li>
<li>加上http basic验证，这个密码不要紧，后面让openvpn自动应答</li>
<li>允许管道模式连接openvpn的1194端口</li>
</ul>
<h3>OpenVPN</h3>
<h4>Server</h4>
<p>服务端倒是不需要很多配置，确定是tcp模式监听连接（我是多开一个openvpn server，子网错开，个人喜欢吧）</p>
<h4>Client</h4>
<p>客户端就要指定使用代理的方式：</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">remote 127.0.0.1 1194
http-proxy YOUR.VPS.IP.HERE.com 8128 pw.txt
http-proxy-retry</pre></div></div>
<p>这个pw.txt是上述的HTTP的认证信息，用户名密码各一行。</p>
<p>现在连接OpenVPN，可以看到连接过程的Log有这么几句，基本就确定OpenVPN over HTTP成功了！</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Sun Mar  4 19:12:58 2012 Attempting to establish TCP connection with 199.101.103.107:8192 [nonblock]
Sun Mar  4 19:12:59 2012 TCP connection established with [IPADDR]:8128
Sun Mar  4 19:12:59 2012 Send to HTTP proxy: 'CONNECT 127.0.0.1:1194 HTTP/1.0'
Sun Mar  4 19:12:59 2012 Attempting Basic Proxy-Authorization
Sun Mar  4 19:13:00 2012 HTTP proxy returned: 'HTTP/1.1 200 Tunnel established'</pre></div></div>
<h1>Related</h1>
<p>最后透露一下我的<strong>科学上网</strong>环境是在跑OpenWRT的路由器上跑VPN，然后配合<a href="http://code.google.com/p/chnroutes/">chnroute</a>的路由表，当然dnsmasq也经过配置负责把国内常用域名的解释交给国内的<code>114.114.114.114</code>服务器，这样基本一回家手机kindle电脑等全都是翻墙环境，而且速度非常良好。</p>
<h1>Reference</h1>
<ul>
<li><a href="http://www.pps.jussieu.fr/~jch/software/polipo/polipo.html">The Polipo Manual</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/break-through-l7qos-with-openvpn-over-http/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>x11vnc - 远程工作站桌面</title>
		<link>http://apt-blog.net/x11vnc_run_vncserver_in_workstation_remotely</link>
		<comments>http://apt-blog.net/x11vnc_run_vncserver_in_workstation_remotely#comments</comments>
		<pubDate>Sun, 05 Feb 2012 10:31:22 +0000</pubDate>
		<dc:creator>BOYPT</dc:creator>
				<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[DE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[vnc]]></category>
		<guid isPermaLink="false">https://apt-blog.net/?p=1151</guid>
		<description><![CDATA[Gnome Desktop Environment的VNC服务开启很容易，仅需点开Desktop Sharing，打个勾就完了。 但是有时候某台工作站没有打开这个VNC服务，只有SSH，但是又必须通过桌面来操作，这时候自带的vino server就好像不容易跑起来。 x11vnc这个小工具就可以派上用场，它对当前的x11 session建立VNC服务，很简单直接运行x11vnc，就等你连接5900端口了。当然，如果一定要指定一个session，有个-display参数可以指定，或者看看x11vnc --help，好长好长～～～]]></description>
			<content:encoded><![CDATA[<p>Gnome Desktop Environment的VNC服务开启很容易，仅需点开<code>Desktop Sharing</code>，打个勾就完了。</p>
<p><a href="http://apt-blog.net/wp-content/uploads/2012/02/vino-preferences.png" rel="lightbox[1151]" title="vino-preferences Gnome默认的VNC配置界面"><img title="vino-preferences Gnome默认的VNC配置界面" alt="vino-preferences Gnome默认的VNC配置界面" src="http://apt-blog.net/wp-content/uploads/2012/02/vino-preferences.png" class="aligncenter" style="width:30%" /></a></p>
<p>但是有时候某台工作站没有打开这个VNC服务，只有SSH，但是又必须通过桌面来操作，这时候自带的vino server就好像不容易跑起来。</p>
<p>x11vnc这个小工具就可以派上用场，它对当前的x11 session建立VNC服务，很简单直接运行x11vnc，就等你连接5900端口了。当然，如果一定要指定一个session，有个<code>-display</code>参数可以指定，或者看看<code>x11vnc --help</code>，好长好长～～～</p>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/x11vnc_run_vncserver_in_workstation_remotely/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nginx + PHP (via php-fpm) on Ubuntu 环境最佳实践</title>
		<link>http://apt-blog.net/best-practise-nginx-php-via-php-fpm-on-ubuntu</link>
		<comments>http://apt-blog.net/best-practise-nginx-php-via-php-fpm-on-ubuntu#comments</comments>
		<pubDate>Thu, 21 Jul 2011 11:01:31 +0000</pubDate>
		<dc:creator>BOYPT</dc:creator>
				<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">http://apt-blog.net/nginx-php-via-php-fpm-on-ubuntu-lucid-%e7%8e%af%e5%a2%83%e6%9c%80%e4%bd%b3%e5%ae%9e%e8%b7%b5</guid>
		<description><![CDATA[Nginx团队维护的PPA源带有PHP 5.3.x的子源，更新迅速，现在在Ubuntu部署Nginx+PHP环境真是太容易了（虽然LAMP更容易，一句apt-get install lamp-server^搞定，别漏了最后的上尖号）。像以前那样跑cgi-fcgi简直弱爆了。 UPDATE: 2012/03/15 Nginx的ppa团队决定不再维护php包了……所以只能用别人的ppa.. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 apt-get install python-software-properties add-apt-repository ppa:nginx/stable #add-apt-repository ppa:nginx/php5 #not valid any more add-apt-repository ppa:brianmercer/php5 &#160; #Ubuntu 10.10 以后可不需添加以上源 &#160; apt-get update apt-get install nginx apt-get install php5-cgi php5-mysql php5-fpm php5-curl php5-mcrypt &#160; #或者你需要更齐全的php包： [...]]]></description>
			<content:encoded><![CDATA[<p><S>Nginx团队维护的PPA源带有PHP 5.3.x的子源，更新迅速，现在在Ubuntu部署Nginx+PHP环境真是太容易了（虽然LAMP更容易，一句<code>apt-get install lamp-server^</code>搞定，别漏了最后的上尖号）</S>。像<a href="http://apt-blog.net/setup_nginx">以前那样</a>跑cgi-fcgi简直弱爆了。</p>
<p>UPDATE: 2012/03/15 Nginx的ppa团队决定不再维护php包了……所以只能用别人的ppa..</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> python-software-properties
add-apt-repository ppa:nginx<span style="color: #000000; font-weight: bold;">/</span>stable
<span style="color: #666666; font-style: italic;">#add-apt-repository ppa:nginx/php5 #not valid any more</span>
add-apt-repository ppa:brianmercer<span style="color: #000000; font-weight: bold;">/</span>php5
&nbsp;
<span style="color: #666666; font-style: italic;">#Ubuntu 10.10 以后可不需添加以上源</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> nginx
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-cgi php5-mysql php5-fpm php5-curl php5-mcrypt
&nbsp;
<span style="color: #666666; font-style: italic;">#或者你需要更齐全的php包：</span>
<span style="color: #666666; font-style: italic;">#aptitude install php5-cgi php5-mysql php5-fpm php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl</span>
&nbsp;
service nginx start
service php5-fpm start</pre></td></tr></table></div>
<h2>FPM Tunning</h2>
<p>php5-fpm默认参数启动的服务器还是比较耗资源的，如果环境不充裕（如512内存以下的VPS），可以做下配置。</p>
<p>这个包的fpm的默认配置文件是<code>/etc/php5/fpm/main.conf</code>，但对子进程的配置是在其包含的<code>/etc/php5/fpm/pool.d/</code>目录内，里面有个<code>www.conf</code>，可以对以下的参数做以下修改：</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">pm = dynamic              ;动态管理php-fpm的子进程
pm.max_children = 5       ;最多的时候开不超过5个
pm.start_servers = 2      ;启动服务时候开2个
pm.min_spare_servers = 2  ;空闲时候最少留2个
pm.max_spare_servers = 5  ;最多留5个
pm.max_requests = 300     ;每个子进程最多处理300个请求就退出换新的子进程。</pre></div></div>
<p>按需调整这些参数可以达到最佳动态分配资源的效果。</p>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/best-practise-nginx-php-via-php-fpm-on-ubuntu/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx+uwsgi架设自用Mercurial hg仓库：hgwebdir</title>
		<link>http://apt-blog.net/mercurial-repo-under-nginx-and-uwsgi</link>
		<comments>http://apt-blog.net/mercurial-repo-under-nginx-and-uwsgi#comments</comments>
		<pubDate>Fri, 11 Mar 2011 07:43:59 +0000</pubDate>
		<dc:creator>BOYPT</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[hg]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[nginx]]></category>
		<guid isPermaLink="false">http://apt-blog.net/mercurial-repo-under-nginx-and-uwsgi</guid>
		<description><![CDATA[Mercurial/hg是分布式版本管理工具之一，如google code等公共代码服务都直接支持。不过公共服务通常都有如公开开源、空间大小等等的限制，如果特殊情况，需要自己在VPS上假设一套，也不太难。 如果单独一个hg仓库，直接运行hg serve就已经是在线仓库，用nginx做的http_proxy反向代理就够了，各种功能齐全。但是要host多个hg仓库，需要用hgwebdir。 Ubuntu当中安装的mercurial已经包含了架设仓库所用的程序，包括cgi/fcgi/wcgi的，主接口在/usr/share/doc/mercurial-common/examples下的hgwebdir.(ws&#124;(f)c)gi。虽然其中的wsgi有效的只有三行。 Mercurial官方Wiki上主要介绍了用apache2来跑cgi方式的仓库，但是作为python的程序，wsgi才是最原生的嘛。用Nginx+uwsgi的方式，资源占用、响应效率等，都要比apache + cgi靠谱。 Nginx+uwsgi的方式很普遍，参见本博客之前的MoinMoin 与 Nginx, fastcgi 与 uwsgi 的配置一文。 但是因为uwsgi处于快速开发过程当中，ppa的打包也还不十分成熟，里面的路径跟以前有些不一样了。 add-apt-repository ppa:nginx/stable add-apt-repository ppa:uwsgi/release apt-get update apt-get install nginx uwsgi-python python-virtualenv mercurial &#160; mkdir -p /var/www/hgwebdir virtualenv /var/www/hgwebdir/python-home &#160; cat &#62;/var/www/hgwebdir/hgwebdir_wsgi.py &#60;&#60; EOF from mercurial import demandimport; demandimport.enable() from mercurial.hgweb.hgwebdir_mod import hgwebdir &#160; class hgwebdir_with_fixed_staticfile(hgwebdir): def __call__(self, env, respond): [...]]]></description>
			<content:encoded><![CDATA[<p>Mercurial/hg是分布式版本管理工具之一，如google code等公共代码服务都直接支持。不过公共服务通常都有如公开开源、空间大小等等的限制，如果特殊情况，需要自己在VPS上假设一套，也不太难。</p>
<p>如果单独一个hg仓库，直接运行hg serve就已经是在线仓库，用nginx做的http_proxy反向代理就够了，各种功能齐全。但是要host多个hg仓库，需要用hgwebdir。</p>
<p>Ubuntu当中安装的mercurial已经包含了架设仓库所用的程序，包括cgi/fcgi/wcgi的，主接口在<code>/usr/share/doc/mercurial-common/examples</code>下的<code>hgwebdir.(ws|(f)c)gi</code>。虽然其中的wsgi有效的只有三行。</p>
<p>Mercurial官方Wiki上主要<a href="http://mercurial.selenic.com/wiki/HgWebDirStepByStep">介绍了用apache2来跑cgi方式的仓库</a>，但是作为python的程序，wsgi才是最原生的嘛。用Nginx+uwsgi的方式，资源占用、响应效率等，都要比apache + cgi靠谱。</p>
<p>Nginx+uwsgi的方式很普遍，参见本博客之前的<a href="http://apt-blog.net/moinmoin-on-nginx-via-fastcgi-and-uwgi">MoinMoin 与 Nginx, fastcgi 与 uwsgi 的配置</a>一文。</p>
<p>但是因为uwsgi处于快速开发过程当中，ppa的打包也还不十分成熟，里面的路径跟以前有些不一样了。</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">add-apt-repository ppa:nginx<span style="color: #000000; font-weight: bold;">/</span>stable
add-apt-repository ppa:uwsgi<span style="color: #000000; font-weight: bold;">/</span>release
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> nginx uwsgi-python python-virtualenv mercurial
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>hgwebdir
virtualenv <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>hgwebdir<span style="color: #000000; font-weight: bold;">/</span>python-home
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>hgwebdir<span style="color: #000000; font-weight: bold;">/</span>hgwebdir_wsgi.py <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb.hgwebdir_mod import hgwebdir
&nbsp;
class hgwebdir_with_fixed_staticfile(hgwebdir):
    def __call__(self, env, respond):
        response = super(self.__class__, self).__call__(env, respond)
        return response[0] if isinstance(response, tuple) else response
&nbsp;
application = hgwebdir_with_fixed_staticfile('/var/www/hgwebdir/hgweb.config')
EOF</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>hgwebdir<span style="color: #000000; font-weight: bold;">/</span>hgweb.config <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
[collections]
/home/hg-repo = /home/hg-repo
&nbsp;
[web]
style = monoblue
allow_archive = gz, zip, bz2
baseurl = /
push_ssl = true
hidden = false
allow_read = *
allow_push = user1 user2
&nbsp;
[extensions]
#highlight =
EOF</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>etc<span style="color: #000000; font-weight: bold;">/</span>uwsgi-python<span style="color: #000000; font-weight: bold;">/</span>apps-enabled<span style="color: #000000; font-weight: bold;">/</span>uwsgi.xml <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
&lt;uwsgi&gt;
  &lt;limit-as&gt;256&lt;/limit-as&gt;
  &lt;processes&gt;6&lt;/processes&gt;
  &lt;memory-report/&gt;
  &lt;vhost/&gt;
  &lt;no-site/&gt;
&lt;/uwsgi&gt;
EOF</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-enabled<span style="color: #000000; font-weight: bold;">/</span>hgwebdir <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
server {
    listen   80;
    client_max_body_size 512m;
    server_name hg.mydomian.com;
    location / {
                include uwsgi_params;
                uwsgi_pass unix:///var/run/uwsgi-python/uwsgi/socket;
                uwsgi_param UWSGI_PYHOME /var/www/hgwebdir/python-home;
                uwsgi_param UWSGI_CHDIR /var/www/hgwebdir/;
                uwsgi_param UWSGI_SCRIPT hgwebdir_wsgi;
                uwsgi_param UWSGI_SCHEME \$scheme;
                uwsgi_param REMOTE_USER \$remote_user;
        }
}
EOF</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>hg-repo
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>hg-repo
hg init example-repo1
hg init example-repo2
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> www-data:www-data <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>hg-repo
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx restart
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>uwsgi-python restart</pre></div></div>
<p>所以，/home/hg-repo下的所有仓库(新建的两个空仓库example-repo1/2)都会被hgwebdir列表在目录上，直接使用其地址就可以pull/push了。</p>
<p>注意的是hgweb.config文件里面的配置，<code>push_ssl = true</code>只允许使用https协议的时候push，也就是需要另外配置一个支持https的nginx。这个属于nginx的基本配置，这里不重提了。</p>
<p>对于不公开的仓库，除了HTTPS，还需要用户名密码，只需要配置nginx的basic http auth，上面命令当中的<code>uwsgi_param REMOTE_USER $remote_user</code>一行配置会把http auth的USER通过协议发送到hgweb，完成其认证过程。</p>
<p>其实hgweb的认证仅仅是用户名的匹配，hgweb.config里面的<code>allow_push = user1 user2</code>是全局设定，各个仓库的<code>.hg/hgrc</code>里面的同样的[web]区下也可以定义allow_push/read，即仓库各自的读写权限。</p>
<p><code>hgweb.config</code>中注释掉的highlight一行，是启动语法高亮插件用的，打开需要先安装<code>python-pygments</code>包，不然会出错。</p>
<p>这个版本的uwsgi程序的log在<code>/var/log/uwsgi-python/uwsgi.log</code>，如果出任何问题，大概看看log的提示按提示去修复即可。</p>
<p><strong>Update: 2011-3-17</strong></p>
<p>原hgwebdir的程序跟wsgi2协议兼容不好，会出现仓库目录的首页里面的静态文件全部无法打开，log里面的信息是<code>invalid WSGI2.0 response size: 1 .</code>。 上述代码中已经修复（见1楼留言。）  <strong>Thank You, Leonid.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/mercurial-repo-under-nginx-and-uwsgi/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Manage multiple wordpresses with new Vimpress</title>
		<link>http://apt-blog.net/manage-multiple-wordpresses-with-new-vimpress</link>
		<comments>http://apt-blog.net/manage-multiple-wordpresses-with-new-vimpress#comments</comments>
		<pubDate>Thu, 10 Mar 2011 07:40:53 +0000</pubDate>
		<dc:creator>BOYPT</dc:creator>
				<category><![CDATA[Blogger Tech]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[vimpress]]></category>
		<guid isPermaLink="false">http://apt-blog.net/manage-multiple-wordpresses-with-new-vimpress</guid>
		<description><![CDATA[Update Vimpress 已经升级到2.x版本，使用、配置都有改进，请关注在vim.org的插件页面： Vimpress had been updated to 2.x, usage and configurations are now different, read the officle page in vim.org: http://www.vim.org/scripts/script.php?script_id=3510 If you noticed Vimpress before and got more than one wordpress to write, must glad now to know this VimRePressed support multiple configs and swith freely. The new VimRePressed (Version: 1.2.0) Changes: Add: [...]]]></description>
			<content:encoded><![CDATA[<p><strong> Update </strong><br />
Vimpress 已经升级到2.x版本，使用、配置都有改进，请关注在vim.org的插件页面： </p>
<p>Vimpress had been updated to 2.x, usage and configurations are now different, read the officle page in vim.org:</p>
<p><a href="http://www.vim.org/scripts/script.php?script_id=3510">http://www.vim.org/scripts/script.php?script_id=3510</a></p>
<hr />
<p>If you noticed <a href="http://apt-blog.net/tag/vimpress">Vimpress</a> before and got more than one wordpress to write, must glad now to know this VimRePressed support multiple configs and swith freely.</p>
<p>The new VimRePressed (Version: 1.2.0) Changes:</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">      Add: MarkdownPreview command to preiview markdown in browser.
      Add: MarkdownNewPost command to convert a markdown
           written post into html and set to the new post view.
      Add: Move blog configs info to personal .vimrc
      Add: Multiple config is now supported, and with :BlogSwitch
           command added.
      Add: Show which blog your editing at :BlogList view.
      Fix: Running :BlogList in the List view got error.</pre></div></div>
<p>Now you got to wirte your blog config in your own ~/.vimrc file. (CAREFUL when your share your vim configure with others then. Use a <code>source my_vimpress.vimrc</code> instead. )</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">let VIMPRESS=[{'username':'user',
              \'password':'pass',
              \'blog_url':'http://your-first-blog.com/'
              \},
              \{'username':'user',
              \'password':'pass',
              \'blog_url':'http://your-second-blog.com/'
              \}]</pre></div></div>
<p>The syntax looks just like python or json, dictionarys in a list(or array), only that line brake need to write in the vim way.</p>
<p>BlogSwitch command rotate you from the first blog to the last, then the first. If you got confused, BlogList command can show you which one you're connecting to.</p>
<p>Then the Markdown support. I added two command to save my time saving .mkd file then convert them into html then check in a browser, MarkdownPreview command can do this for me. When flawless, the MarkdownNewPost command switch me to the new post view with all thing I write into html, which is ready to publish.</p>
<p>Download: <a href="http://code.google.com/p/ptcoding/downloads/detail?name=vimpress_1.2.5-r55.zip">from google code</a></p>
<p>SVN Version also available:</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> checkout http:<span style="color: #000000; font-weight: bold;">//</span>ptcoding.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span>vimpress</pre></td></tr></table></div>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/manage-multiple-wordpresses-with-new-vimpress/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>使用wp-super-cache插件静态缓冲的nginx rewrite规则</title>
		<link>http://apt-blog.net/nginx-rewrite-rules-for-wp-super-cache</link>
		<comments>http://apt-blog.net/nginx-rewrite-rules-for-wp-super-cache#comments</comments>
		<pubDate>Thu, 03 Mar 2011 14:39:07 +0000</pubDate>
		<dc:creator>BOYPT</dc:creator>
				<category><![CDATA[Blogger Tech]]></category>
		<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">http://apt-blog.net/nginx-rewrite-rules-for-wp-super-cache</guid>
		<description><![CDATA[WordPress的缓冲插件wp-super-cache默认支持apahce的缓冲方式，在生成了静态页面数据后，通过.htaccess的规则直接让apache读取静态文件，完全不经过PHP，可以很大的提高博客的页面性能。 但是Nginx的改写规则就没这么容易让代码来配置了，虽然wp-super-cache的第二种缓存方式就是为这种使用环境设计，但实际上是用了PHP来提供静态数据了，在使用apache benchmark压力的时候，php-cgi依然占很高的CPU占有率。 通过编写nginx的rewrite规则还是可以让nginx直接读取静态文件，参考来自Code Exchange: nginx rewrite rules for WordPress + WP Super Cache，这里的配置被很多地方引用过，但实际尝试使用过程看到那里面的代码还需要微调。 server { listen 80; server_name apt-blog.net; root /var/www/pt-sites/wordpress; index index.html index.htm index.php; location / { # enable search for precompressed files ending in .gz # nginx needs to be complied using –-with-http_gzip_static_module # for this to work, comment out if using [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress的缓冲插件wp-super-cache默认支持apahce的缓冲方式，在生成了静态页面数据后，通过.htaccess的规则直接让apache读取静态文件，完全不经过PHP，可以很大的提高博客的页面性能。</p>
<p>但是Nginx的改写规则就没这么容易让代码来配置了，虽然wp-super-cache的第二种缓存方式就是为这种使用环境设计，但实际上是用了PHP来提供静态数据了，在使用apache benchmark压力的时候，php-cgi依然占很高的CPU占有率。</p>
<p>通过编写nginx的rewrite规则还是可以让nginx直接读取静态文件，参考来自<a href="http://forum.slicehost.com/comments.php?DiscussionID=2087">Code Exchange: nginx rewrite rules for WordPress + WP Super Cache</a>，这里的配置被很多地方引用过，但实际尝试使用过程看到那里面的代码还需要微调。</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">    server {
        listen          80;
        server_name     apt-blog.net;
        root    /var/www/pt-sites/wordpress;
        index   index.html index.htm index.php;
        location / {
                # enable search for precompressed files ending in .gz
                # nginx needs to be complied using –-with-http_gzip_static_module
                # for this to work, comment out if using nginx from aptitude
                gzip_static on;
&nbsp;
# if the requested file exists, return it immediately
                if (-f $request_filename) {
                        break;
                }
&nbsp;
set $supercache_file '';
                set $supercache_uri $request_uri;
&nbsp;
if ($request_method = POST) {
                        set $supercache_uri '';
                }
&nbsp;
# Using pretty permalinks, so bypass the cache for any query string
                if ($query_string) {
                        set $supercache_uri '';
                }
&nbsp;
if ($http_cookie ~* &quot;comment_author_|wordpress|wp-postpass_&quot; ) {
                        set $supercache_uri '';
                }
&nbsp;
# !!!! IMPORTANT
                # if we haven't bypassed the cache, specify our supercache file
                if ($supercache_uri ~ ^(.+)$) {
                        set $supercache_file /wp-content/cache/supercache/$http_host/$1/index.html;
                }
&nbsp;
# only rewrite to the supercache file if it actually exists
                if (-f $document_root$supercache_file) {
                        rewrite ^(.*)$ $supercache_file break;
                }
&nbsp;
# all other requests go to Wordpress
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?q=$1 last;
                }
&nbsp;
}
        location ~ \.php$ {
              include        fastcgi_params;
              fastcgi_pass   127.0.0.1:9000;
              fastcgi_index  index.php;
              fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }
    }</pre></div></div>
<p><strong>需要重点关注的是<code>set $supercache_uri</code>这一行，这里的路径是wp-super-cache生成静态文件的路径，配置文件起作用的时候，这个路径会和$document_root组成最终静态文件的绝对路径，最终输出文件。所以如果这个路径不对的话，最终还是交给了<code>index.php</code>，缓冲就不起作用了。</strong></p>
<p>wp-super-cache在wordpress目录<code>/wp-content/cache/supercache/$http_host/</code>下生成了各个请求url的目录，目录下是一个index.html静态文件，可以在wordpress工作时候，在这个目录下用命令<code>watch find</code>观察（在缓冲不多的情况下），总之小心的把这个路径写好，因为估计每个博客的permanent link的样式都不一样，wp-super-cache生成的目录也不一样，需要仔细调试一下。</p>
<p>当然这里的规则并没有安全包含了wp-super-cache 插件的功能，比如识别手机客户端之类的，如果需要还得仔细根据插件生成的.htaccess规则来添加到nginx。</p>
<p>完成后用apache benchmark压一下，Request per second应该很容易上百，而且php-cgi应该不会出现在top的列表前面了，CPU应该集中在nginx的子进程上，而且都是个位数CPU占有率，系统的load非常低。</p>
<p>Tips: 发现测试结果不对时，可以尝试删除/wp-content/cache整个目录，让wp重新生成所有缓冲。</p>
<p>顺便说一下，如果仅使用ab测试压力，用不着安装整个apache2，只需要<code>apt-get install apache2-utils</code>。</p>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/nginx-rewrite-rules-for-wp-super-cache/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>黑莓续断膏 MDS服务器的Linux版本</title>
		<link>http://apt-blog.net/blackberry_broken_net_fix_server_for_linux</link>
		<comments>http://apt-blog.net/blackberry_broken_net_fix_server_for_linux#comments</comments>
		<pubDate>Wed, 23 Feb 2011 10:18:43 +0000</pubDate>
		<dc:creator>BOYPT</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mds]]></category>
		<category><![CDATA[黑莓]]></category>
		<guid isPermaLink="false">http://apt-blog.net/blackberry_broken_net_fix_server_for_linux</guid>
		<description><![CDATA[黑莓系统5.0以上系统在没有购买使用黑莓网络服务的手机上的断网现象一直比较恼人。几个月前有人做出了“黑莓续断膏”，原理是自架一台服务器，程序模拟MDS服务的简单回应，可以忽悠手机继续在线。 5.0系统断网自动修复程序黑莓断续膏(AntiBrokenNet！) BrokenNetFixup断网修复工具 区别是前者后台自动修复，后者要手动运行修复。 从网友的留言看出，虽然软件虽然有效，但没有稳定的服务器，软件刚出现时候确实有一批地址提供了服务，但很快就失效了。北京小C这里提供了模拟MDS服务器的程序，是VC写的一个小UDP服务器，虽然原理很简单，但用一台Windows的服务器来跑成本太高了，当然很难稳定提供。 其实服务只是很简单的几行代码，稍微改了一下就可以在Linux下面运行。一台低端Linux VPS的费用大概一年200RMB，这个费用对大多数人来说都不是什么问题的，所以推荐想要稳定防断网服务器的人去弄一台，一台可以很多人共享了。VPS侦探 、Lowendbox上有很多这样的推荐。 Linux版本的MDS服务器代码在Google Code上，可以直接下载。 在服务器（Debian/Ubuntu系统）上编译并运行： 1 2 3 4 5 sudo apt-get install build-essential wget http://ptcoding.googlecode.com/svn/trunk/mds_server.c gcc -Wall -o mds_server mds_server.c sudo cp mds_server /usr/local/bin/ /usr/local/bin/mds_server 现在可以设置手机的续断软件使用这个服务器来连接断网测试了，手机连接的时候，会实时打印出手机的连接信息跟PIN码。 当然最好把程序加入系统自动启动： sudo touch /var/log/mds_server.log sudo chown nobody /var/log/mds_server.log sudo sed -i '/^exit 0/isu nobody -c &#34;nohup /usr/local/bin/mds_server &#62;&#62;/var/log/mds_server.log &#38;&#34;' /etc/rc.local 这样程序会在系统启动后自动在后台运行，运行的LOG会记录在/var/log/mds_server.log文件当中。 下面也无偿提供一枚MDS服务器，就是跑在我的Linux服务器上的。 [...]]]></description>
			<content:encoded><![CDATA[<p>黑莓系统5.0以上系统在没有购买使用黑莓网络服务的手机上的断网现象一直比较恼人。几个月前有人做出了“黑莓续断膏”，原理是自架一台服务器，程序模拟MDS服务的简单回应，可以忽悠手机继续在线。</p>
<ul>
<li><a href="http://www.bbercn.com/auto-fix-network-problems-by-antibrokennet.html">5.0系统断网自动修复程序黑莓断续膏(AntiBrokenNet！)</a></li>
<li><a href="http://www.bjxiaoc.cn/index.php/archives/11437">BrokenNetFixup断网修复工具</a></li>
</ul>
<p>区别是前者后台自动修复，后者要手动运行修复。</p>
<p>从网友的留言看出，虽然软件虽然有效，但没有稳定的服务器，软件刚出现时候确实有一批地址提供了服务，但很快就失效了。<a href="http://www.bjxiaoc.cn/index.php/archives/11437">北京小C</a>这里提供了模拟MDS服务器的程序，是VC写的一个小UDP服务器，虽然原理很简单，但用一台Windows的服务器来跑成本太高了，当然很难稳定提供。</p>
<p>其实服务只是很简单的几行代码，稍微改了一下就可以在Linux下面运行。一台低端Linux VPS的费用大概一年200RMB，这个费用对大多数人来说都不是什么问题的，所以推荐想要稳定防断网服务器的人去弄一台，一台可以很多人共享了。<a href="http://www.vpser.net/">VPS侦探</a>  、<a href="http://www.lowendbox.com/">Lowendbox</a>上有很多这样的推荐。</p>
<p>Linux版本的MDS服务器代码在<a href="http://code.google.com/p/ptcoding/source/browse/trunk/mds_server.c">Google Code</a>上，可以<a href="http://ptcoding.googlecode.com/svn/trunk/mds_server.c">直接下载</a>。</p>
<p>在服务器（Debian/Ubuntu系统）上编译并运行：</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> build-essential
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>ptcoding.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span>mds_server.c
<span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-Wall</span> <span style="color: #660033;">-o</span> mds_server mds_server.c
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> mds_server <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mds_server</pre></td></tr></table></div>
<p>现在可以设置手机的续断软件使用这个服务器来连接断网测试了，手机连接的时候，会实时打印出手机的连接信息跟PIN码。</p>
<p>当然最好把程序加入系统自动启动：</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>mds_server.log
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> nobody <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>mds_server.log
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/^exit 0/isu nobody -c &quot;nohup /usr/local/bin/mds_server &gt;&gt;/var/log/mds_server.log &amp;&quot;'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.local</pre></div></div>
<p>这样程序会在系统启动后自动在后台运行，运行的LOG会记录在<code>/var/log/mds_server.log</code>文件当中。</p>
<p>下面也无偿提供一枚MDS服务器，就是跑在我的Linux服务器上的。</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">地址：119.134.250.11
端口：19781</pre></div></div>
<p>另外服务端口可以修改源代码里面的宏：</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define LOCAL_SERVER_PORT 19781</span></pre></td></tr></table></div>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/blackberry_broken_net_fix_server_for_linux/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MoinMoin 与 Nginx, fastcgi 与 uwsgi 的配置</title>
		<link>http://apt-blog.net/moinmoin-on-nginx-via-fastcgi-and-uwgi</link>
		<comments>http://apt-blog.net/moinmoin-on-nginx-via-fastcgi-and-uwgi#comments</comments>
		<pubDate>Wed, 13 Oct 2010 13:38:56 +0000</pubDate>
		<dc:creator>BOYPT</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[moinmoin]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[uwgi]]></category>
		<category><![CDATA[wiki]]></category>
		<guid isPermaLink="false">http://apt-blog.net/moinmoin-on-nginx-via-fastcgi-and-uwgi</guid>
		<description><![CDATA[给自己架了个Wiki http://wiki.ptsang.net作为自己的知识管理工具。虽然这个博客本来就是工具之一，也累积了快两年了，但经常碰到有些小东西，不值得为之写篇博客，很有用，但用完就忘记。个人wiki适合做写细小的笔记，当累积一定的时候还可以整理成博客。 Wiki我选择了用Python的MoinMoin，一定程度上受CPYUG社区 ZoomQuiet 大妈的推荐影响，首次试用感觉非常impresive，所以就定了。再加上 GraphViz 工具的支持，实在的强大。 在vps上服务，肯定是无视apache的，内存有限。之前架设过用来上Twitter奶瓶腿，是Nginx + php-cgi的方案，nginx是必须的。 Python跟web前端的架构方式有太多选择了，五花八门，MoinMoin的发行包里面都提供了moin.cgi moin.scgi moin.ajp moin.fcgi moin.wsgi等多种启动方式。MoinMoin里面全部通过内置的flup作为中间件提供这些接口，目前我仅尝试使用了fastcgi和wsgi。 虽然解压了moin的源码包就可以直接运行里面的wikiserver.py来本地访问了，但在服务器上通常是由nginx/lighttpd等服务来综合转发。php的话是通过spawn-fcgi启动一些php-cgi的进程，服务器接受到动态的请求就通过本地socket跟php-cgi通讯，返回的结果展现回给客户。php-cgi是使用FastCGI协议的。 MoinMoin 源码当中wiki/server/moin.fcgi就是一个类似php-cgi功能的fastcgi服务，类似地可以使用spawn-fcgi来启动moin.fcgi，作为后端的处理进程。 Running MoinMoin Wiki with Nginx via FastCGI and Flup该文章很形象解释了fastcgi的角色，以及提供了一段很方便的服务脚本来启动spawn-fcgi。 Client ----> Nginx Web Frontend -----------+ &#124; fastcgi_pass \&#124;/ +-------------------------+ moin.fcgi &#124; spawn-fcgi-moin.socket &#124; spawn-fcgi ---------------> &#124; or &#124; &#124; localhost:port &#124; +-------------------------+ 但是文章当中的nginx配置不完整，而且复杂了，这是我的配置： server { listen 80; [...]]]></description>
			<content:encoded><![CDATA[<p>给自己架了个Wiki <a href="http://wiki.ptsang.net">http://wiki.ptsang.net</a>作为自己的知识管理工具。虽然这个博客本来就是工具之一，也累积了快两年了，但经常碰到有些小东西，不值得为之写篇博客，很有用，但用完就忘记。个人wiki适合做写细小的笔记，当累积一定的时候还可以整理成博客。</p>
<p>Wiki我选择了用Python的MoinMoin，一定程度上受CPYUG社区<a href="http://wiki.woodpecker.org.cn/moin/ZoomQuiet"> ZoomQuiet </a>大妈的推荐影响，首次试用感觉非常impresive，所以就定了。再加上<a href="http://wiki.woodpecker.org.cn/moin/GraphViz"> GraphViz </a>工具的支持，实在的强大。</p>
<p>在vps上服务，肯定是无视apache的，内存有限。之前架设过用来上Twitter奶瓶腿，是Nginx + php-cgi的方案，nginx是必须的。</p>
<p>Python跟web前端的架构方式有太多选择了，五花八门，MoinMoin的发行包里面都提供了<code>moin.cgi</code> <code>moin.scgi</code> <code>moin.ajp</code> <code>moin.fcgi</code> <code>moin.wsgi</code>等多种启动方式。MoinMoin里面全部通过内置的flup作为中间件提供这些接口，目前我仅尝试使用了fastcgi和wsgi。</p>
<p>虽然解压了moin的源码包就可以直接运行里面的<code>wikiserver.py</code>来本地访问了，但在服务器上通常是由nginx/lighttpd等服务来综合转发。php的话是通过<code>spawn-fcgi</code>启动一些php-cgi的进程，服务器接受到动态的请求就通过本地socket跟php-cgi通讯，返回的结果展现回给客户。php-cgi是使用FastCGI协议的。</p>
<p>MoinMoin 源码当中<code>wiki/server/moin.fcgi</code>就是一个类似php-cgi功能的fastcgi服务，类似地可以使用<code>spawn-fcgi</code>来启动moin.fcgi，作为后端的处理进程。</p>
<p><a href="http://dotimes.com/iscale/2010/07/running-moinmoin-wiki-with-nginx-via-fastcgi-and-flup.html">Running MoinMoin Wiki with Nginx via FastCGI and Flup</a>该文章很形象解释了fastcgi的角色，以及提供了一段很方便的服务脚本来启动<code>spawn-fcgi</code>。</p>
<pre>
Client ----> Nginx Web Frontend -----------+
                                           | fastcgi_pass
                                          \|/
                            +-------------------------+
              moin.fcgi     | spawn-fcgi-moin.socket  |
spawn-fcgi ---------------> |           or            |
                            |     localhost:port      |
                            +-------------------------+
</pre>
<p>但是文章当中的nginx配置不完整，而且复杂了，这是我的配置：</p>
<div class="wp_syntax"><div class="code"><pre class="nginx" style="font-family:monospace;">server {
        listen   80; ## listen for ipv4
        server_name  wiki.apt-blog.net;
&nbsp;
        access_log  /var/log/nginx/wiki.apt-blog.net.access.log;
        error_log   /var/log/nginx/wiki.apt-blog.net.error_log;
&nbsp;
        location / {
                include fastcgi_params;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_param SCRIPT_NAME /;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                if (!-f $request_filename) {
                        fastcgi_pass unix:/var/run/spawn-fcgi-moin.socket;
                }
        }
}</pre></div></div>
<p>当然那文章中的配置有考虑对静态文件直接由nginx服务，不通过flup这一层，有一定优化，这里省去了这些。其实增多一个<code>/moin_static193</code>(据版本号不同而不同)的location即可，可参考后面使用uwsgi做服务时候的配置。</p>
<p>文章还提到<code>wikiconfig.py</code>里面一个<code>fix_script_name</code>变量，是1.9版本新加入的，需要xxx.com/wiki这样访问的童鞋就不用像以前版本那样要在nginx配置里面写一大堆东西了。</p>
<p>Fastcgi就这么多，不算太复杂。Fastcgi虽然很流行，但弊端不少，首先是速度，在一台虚拟机上测试，用ab居然跑出每秒20个请求的速度……虽然平均下来还是有5、60次，但真的，唉。php-cgi还支持产生多个工作进程以并行和均衡请求，提高效率，fastcgi似乎就没这样的东西了。</p>
<p>刚好这天<a href="http://obmem.info/">observer专栏杂记</a>写了一篇<a href="http://obmem.info/?p=703">配置Nginx＋uwsgi更方便地部署python应用</a>，当中也提到<code>fcgi</code>和 <code>mod_python</code>的各种不便，然后介绍了<code>uwgi</code>，高性能、多应用。</p>
<p>uwgi充当了python解析器的角色，使用wsgi的接口和Python程序交互，这个过程中做了优化，和上层nginx之间则设计了更加轻量的协议。nginx0.8.40以后官方默认带了uwgi的协议模块，所以使用很方便。</p>
<p>uwgi的文档有些简略，但是重点都是在<a href="http://projects.unbit.it/uwsgi/wiki/Example">wiki/Example</a>里面了。 MoinMoin在uwgi的配置在其中一句带过：</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>uwsgi <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>moin.sock <span style="color: #660033;">--wsgi-file</span> wiki<span style="color: #000000; font-weight: bold;">/</span>server<span style="color: #000000; font-weight: bold;">/</span>moin.wsgi <span style="color: #660033;">-M</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">4</span></pre></div></div>
<p>uwgi的-w参数是把某个py文件作为module，import使用，但是wsgi文件不被认识，所以新版里面多了这么个<code>--wsgi-file</code>参数。但是如果是多站点呢！</p>
<p>nginx配置的虚拟主机里面的<code>uwsgi_param UWSGI_SCRIPT</code>参数会让uwgi按模块导入名称，相当于命令行里面的<code>-w</code>，但是moinmoin的moin.wsgi文件，不是py结尾，只能用<code>--wsgi-file</code>参数。扫了一圈uwgi的<a href="http://projects.unbit.it/uwsgi/wiki/Example">wiki/Example</a>和<a href="http://projects.unbit.it/uwsgi/wiki/RunOnNginx">RunOnNginx</a>，都没提到这个问题，倒是在<a href="http://projects.unbit.it/uwsgi/wiki/RunPinax">这里</a>提到在旧版的uwgi当中没有<code>--wsgi-file</code>参数，<strong><em>需要把wsgi文件改名成py结尾来导入</em></strong>，好吧，确实那样成功了。</p>
<p>至于性能，一开始我发现uwgi占的内存也不少，一个worker时候就占了20M多的内存，所以没开更多的工作进程；Fastcgi也差不多，然后用Apache Benchmark测试，好像两者区别不大。于是看了下<a href="http://www.peterbe.com/plog/fcgi-vs-gunicorn-vs-uwsgi">fcgi vs. gunicorn vs. uWSGI的测评</a>，才发现uwgi要开多个worker进程才有性能！于是开了8个，性能出来了，秒请求马上就上千！ 显然是uwgi打开了多个进程，充分利用了机器的CPU，还做了均衡请求。</p>
<p>最后，我的Wiki使用uwgi后的nginx配置：</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="nginx" style="font-family:monospace;">server {
    server_name  wiki.apt-blog.net;
    access_log  /var/log/nginx/wiki.apt-blog.net.access.log;
    error_log   /var/log/nginx/wiki.apt-blog.net.error_log;
    location / {
        include uwsgi_params;
        #uwsgi_pass 127.0.0.1:9096;
        uwsgi_pass unix:///tmp/uswgi.sock;
        uwsgi_param UWSGI_PYHOME /usr/local/lib/moinmoin;
        uwsgi_param UWSGI_CHDIR /var/local/wiki-moinmoin/server;
        uwsgi_param UWSGI_SCRIPT moin_wsgi;
    }
    location /moin_static193/ {
        alias /usr/local/lib/moinmoin/lib/python2.6/site-packages/MoinMoin/web/static/htdocs/;
    }
}</pre></td></tr></table></div>
<p>完整配置指南：</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#安装</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-s</span>
add-apt-repository ppa:nginx<span style="color: #000000; font-weight: bold;">/</span>stable
add-apt-repository ppa:uwsgi<span style="color: #000000; font-weight: bold;">/</span>release
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> nginx uwsgi-python python-virtualenv
&nbsp;
<span style="color: #666666; font-style: italic;">#组件配置</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>etc<span style="color: #000000; font-weight: bold;">/</span>uwsgi-python<span style="color: #000000; font-weight: bold;">/</span>apps-enabled<span style="color: #000000; font-weight: bold;">/</span>uwsgi.xml <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
&lt;uwsgi&gt;
  &lt;limit-as&gt;256&lt;/limit-as&gt;
  &lt;processes&gt;6&lt;/processes&gt;
  &lt;memory-report/&gt;
  &lt;vhost/&gt;
  &lt;no-site/&gt;
&lt;/uwsgi&gt;
EOF</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-enabled<span style="color: #000000; font-weight: bold;">/</span>moinmoin <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
server {
    listen   80;
    access_log  /var/log/nginx/wiki.access_log;
    error_log   /var/log/nginx/wiki.error_log;
&nbsp;
    client_max_body_size 64;
    server_name wiki.mydomian.com;
    location / {
                include uwsgi_params;
                uwsgi_pass unix:///var/run/uwsgi-python/uwsgi/socket;
                uwsgi_param UWSGI_PYHOME /var/www/moinmoin/python-home/;
                uwsgi_param UWSGI_CHDIR /var/www/moinmoin/;
                uwsgi_param UWSGI_SCRIPT moin_wsgi;
                uwsgi_param UWSGI_SCHEME $scheme;
                uwsgi_param REMOTE_USER $remote_user;
        }
}
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Python环境预备</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>moinmoin
virtualenv <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>moinmoin<span style="color: #000000; font-weight: bold;">/</span>python-home
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>static.moinmo.in<span style="color: #000000; font-weight: bold;">/</span>files<span style="color: #000000; font-weight: bold;">/</span>moin-1.9.3.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xvfz moin-1.9.3.tar.gz
<span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>moinmoin<span style="color: #000000; font-weight: bold;">/</span>python-env<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>activate
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>moin-1.9.3
python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span>
deactivate
&nbsp;
<span style="color: #666666; font-style: italic;">#MoinMoin环境</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>moin-1.9.3<span style="color: #000000; font-weight: bold;">/</span>wiki <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>moinmoin
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>moinmoin<span style="color: #000000; font-weight: bold;">/</span>wiki
<span style="color: #c20cb9; font-weight: bold;">cp</span> config<span style="color: #000000; font-weight: bold;">/</span>wikiconfig.py wikiconfig.py
<span style="color: #c20cb9; font-weight: bold;">cp</span> server<span style="color: #000000; font-weight: bold;">/</span>moin.wsgi moin_wsgi.py
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/# a2)/isys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))'</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#可选</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> config server
&nbsp;
<span style="color: #666666; font-style: italic;">#重启</span>
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx restart
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>uwsgi-python restart</pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/moinmoin-on-nginx-via-fastcgi-and-uwgi/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.674 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-18 21:32:44 -->
<!-- Compression = gzip -->
