<?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; nginx</title>
	<atom:link href="http://www.54chen.com/tag/nginx/feed" rel="self" type="application/rss+xml" />
	<link>http://www.54chen.com</link>
	<description>PHP、JAVA、缓存、架构、经验、分享</description>
	<lastBuildDate>Fri, 10 Feb 2012 12:21:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>nginx防hashdos模块使用帮助</title>
		<link>http://www.54chen.com/_linux_/nginx-hashdos-help.html</link>
		<comments>http://www.54chen.com/_linux_/nginx-hashdos-help.html#comments</comments>
		<pubDate>Tue, 10 Jan 2012 03:48:30 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[hashdos]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/nginx-hashdos-help.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>经过上周一周朋友们帮忙测试和bug fix，nginx_http_hashdos_module已经达到可以线上使用的水平，下面是使用记录。 下载 #wget --no-check-certificate https://github.com/54chen/nginx-http-hashdos-module/zipball/master #mv master nginx_hashdos.zip #unzip nginx_hashdos.zip 编译安装 #tar zxvf nginx-1.0.xx.tar.gz #cd nginx-1.0.xx/ #./configure --prefix=/opt/soft/nginx --with-pcre --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=../54chen-nginx-http-hashdos-module-f84d909 #make &#038;&#038; make install 配置注意事项 在http段，增加如下： hashdos on; body_max_count 1000; 在各自的location段，要按照业务情况来加： client_body_buffer_size 2m; client_max_body_size 2m; &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://wiki.nginx.org/local/nginx-logo.png" alt="nginx,hashdos" /><br />
经过上周一周朋友们帮忙测试和bug fix，nginx_http_hashdos_module已经达到可以线上使用的水平，下面是使用记录。<br />
<strong>下载</strong></p>
<blockquote><p>#wget --no-check-certificate https://github.com/54chen/nginx-http-hashdos-module/zipball/master<br />
#mv master nginx_hashdos.zip<br />
#unzip nginx_hashdos.zip</p></blockquote>
<p><strong>编译安装</strong></p>
<blockquote><p>#tar zxvf nginx-1.0.xx.tar.gz<br />
#cd nginx-1.0.xx/<br />
#./configure --prefix=/opt/soft/nginx --with-pcre --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=../54chen-nginx-http-hashdos-module-f84d909<br />
#make &#038;&#038; make install</p></blockquote>
<p><strong>配置注意事项</strong><br />
在http段，增加如下：</p>
<blockquote><p>
hashdos on;<br />
body_max_count 1000;
</p></blockquote>
<p>在各自的location段，要按照业务情况来加：</p>
<blockquote><p>client_body_buffer_size 2m;<br />
client_max_body_size 2m;</p></blockquote>
<p>*上述两个值一定要相等。</p>
<p>如果是普通的discuz，上传上限是1m的，可以修改为1m。<br />
如果是没有上传功能的普通网站，建议修改为512k。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/nginx-hashdos-help.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx防hashdos模块释出</title>
		<link>http://www.54chen.com/web-ral/nginx-hashdos-module.html</link>
		<comments>http://www.54chen.com/web-ral/nginx-hashdos-module.html#comments</comments>
		<pubDate>Fri, 06 Jan 2012 03:16:21 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[WEB相关]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[hashdos]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://www.54chen.com/web-ral/nginx-hashdos-module.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>2012.1.7 更新 编译的时候推荐使用nginx-1.0以上版本，不要加--with-debug参数编译，（感谢agentzh指出）。 hashdos这个事，严格意义上不是各种语言的错了（不过perl的确处理得很好），但是用nginx来擦屁股要干净些。 借鉴tomcat的作法，实现了下面这个nginx-http-hashdos-module，通过设置hashdos（默认on）的开关和body_max_count(默认值1000)，对nginx后面的服务进行安全防护，相比对php或者java进行patch，这或许是最好的办法了。 nginx-http-hashdos-module项目地址 https://github.com/54chen/nginx-http-hashdos-module 如何使用 1.下载zip后保存到一个目录，如~/nginx-http-hashdos-module。 2.cd nginx-1.0.9/ 3.重新编译和安装nginx ./configure --prefix=/opt/soft/nginx --with-pcre --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=/path_to/nginx-http-hashdos-module/ &#038;&#038; make &#038;&#038; make install 4.配置打开： hashdos on; body_max_count 1000; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://wiki.nginx.org/local/nginx-logo.png" alt="nginx hashdos" /><br />
<font color=blue>2012.1.7 更新<br />
编译的时候推荐使用nginx-1.0以上版本，不要加--with-debug参数编译，（感谢agentzh指出）。</font></p>
<p>hashdos这个事，严格意义上不是各种语言的错了（不过perl的确处理得很好），但是用nginx来擦屁股要干净些。<br />
借鉴tomcat的作法，实现了下面这个nginx-http-hashdos-module，通过设置hashdos（默认on）的开关和body_max_count(默认值1000)，对nginx后面的服务进行安全防护，相比对php或者java进行patch，这或许是最好的办法了。</p>
<p><strong>nginx-http-hashdos-module项目地址</strong><br />
<a href="https://github.com/54chen/nginx-http-hashdos-module">https://github.com/54chen/nginx-http-hashdos-module</a></p>
<p><strong>如何使用</strong><br />
1.下载zip后保存到一个目录，如~/nginx-http-hashdos-module。<br />
2.cd nginx-1.0.9/<br />
3.重新编译和安装nginx<br />
./configure --prefix=/opt/soft/nginx --with-pcre --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=/path_to/nginx-http-hashdos-module/ &#038;&#038; make &#038;&#038; make install<br />
4.配置打开：<br />
        hashdos on;<br />
	body_max_count 1000;<br />
	location ~ \.php$ {<br />
          fastcgi_pass 127.0.0.1:9000;<br />
          fastcgi_index index.php;<br />
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br />
          include /opt/soft/nginx/conf/fastcgi_params;<br />
	  client_body_buffer_size  2m;<br />
	  client_max_body_size     2m;<br />
        }</p>
<p><strong>注意事项</strong><br />
因为计算参数都在内存中进行，所以client_body_buffer_size 与 client_max_body_size 的值一定要相等。推荐2m。</p>
<p><strong>TODO</strong><br />
改进in-file时的post分析。</p>
<p><strong>原理</strong><br />
介于微博上有网友对此文扫一眼之后以为是简单通过client_body_buffer_size和client_max_body_size来做的判断，特加此节。<br />
nginx-reqeust-body在接到请求时，根据header中的声明，判断是保存在内存还是在硬盘中，当大小超过两个buf和client_body_buffer_size大小时，会写入临时文件。<br />
防止hashdos的终极目标是filter用户的输入，所以对用户的输入参数数量进行计数。超过1000（body_max_count的默认数量）时，返回一个413给攻击者。希望不要再渔到各种高级工程师。</p>
<p><a href="https://github.com/54chen/nginx-http-hashdos-module">https://github.com/54chen/nginx-http-hashdos-module</a></p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/web-ral/nginx-hashdos-module.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>[nginx]如何在access log中记录post请求的参数</title>
		<link>http://www.54chen.com/web-ral/nginx-access-log-post.html</link>
		<comments>http://www.54chen.com/web-ral/nginx-access-log-post.html#comments</comments>
		<pubDate>Thu, 06 Jan 2011 15:46:09 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[WEB相关]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[post]]></category>

		<guid isPermaLink="false">http://www.54chen.com/web-ral/nginx-access-log-post.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>移动互联网行业开发过程中，服务端经常会需要检查是否收到请求，收到什么样的请求，最简单的办法就是看nginx的access log，常见的nginx配置中access log一般都只有GET请求的参数，而POST请求的参数却不行。 http://wiki.nginx.org/NginxHttpCoreModule#.24request_body $request_body This variable(0.7.58+) contains the body of the request. The significance of this variable appears in locations with directives proxy_pass or fastcgi_pass. 正如上文件所示，只需要使用$request_body即可打出post的数据，在现存的server段加上下面的设置即可： log_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_body "$http_referer" "$http_user_agent" $http_x_forwarded_for'; &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://wiki.nginx.org/local/nginx-logo.png" alt="nginx log post data" /></p>
<p>移动互联网行业开发过程中，服务端经常会需要检查是否收到请求，收到什么样的请求，最简单的办法就是看nginx的access log，常见的nginx配置中access log一般都只有GET请求的参数，而POST请求的参数却不行。<br />
<a href="http://wiki.nginx.org/NginxHttpCoreModule#.24request_body">http://wiki.nginx.org/NginxHttpCoreModule#.24request_body</a></p>
<blockquote><p>
$request_body</p>
<p>This variable(0.7.58+) contains the body of the request. The significance of this variable appears in locations with directives proxy_pass or fastcgi_pass. </p></blockquote>
<p>正如上文件所示，只需要使用$request_body即可打出post的数据，在现存的server段加上下面的设置即可：</p>
<blockquote><p><code><br />
   log_format  access  '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_body  "$http_referer" "$http_user_agent" $http_x_forwarded_for';<br />
   access_log  logs/test.access.log  access;</code></p></blockquote>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/web-ral/nginx-access-log-post.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>nginx.conf控制指定的代理ip和ip访问的设置手记</title>
		<link>http://www.54chen.com/_linux_/nginx-conf-ip-setting.html</link>
		<comments>http://www.54chen.com/_linux_/nginx-conf-ip-setting.html#comments</comments>
		<pubDate>Mon, 18 Oct 2010 01:35:23 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[conf]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/nginx-conf-ip-setting.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>工作中有一次用到利用nginx的配置来让只有公司ip的访问才能打开指定的后台url，于是有了下面的记录。 在nginx中if很弱，http://www.nginxcn.com/doc/standard/httprewrite.html，基本上不能写太复杂的条件或者是嵌套。 因为公司我(54chen)网络的设置，过去打到服务器的ip有可能是几个ip，同时也有可能是代理的ip，所以在if判断的时候，可能有多个条件。 location /administrator { #log_format www_54chen_com '$remote_addr - $remote_user [$time_local] $request ' # '"$status" $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; # access_log /data/www.log www_54chen_com; set $fuck 0; if ($remote_addr = '1.1.1.1'){ set $fuck 1; } if ($remote_addr = &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img01.taobaocdn.com/imgextra/i1/T1nZJOXfFJXXcYn1U9_103242.jpg" alt="nginx conf" /></p>
<p>工作中有一次用到利用nginx的配置来让只有公司ip的访问才能打开指定的后台url，于是有了下面的记录。</p>
<p>在nginx中if很弱，http://www.nginxcn.com/doc/standard/httprewrite.html，基本上不能写太复杂的条件或者是嵌套。</p>
<p>因为公司我(<a href="http://www.54chen.com">54chen</a>)网络的设置，过去打到服务器的ip有可能是几个ip，同时也有可能是代理的ip，所以在if判断的时候，可能有多个条件。</p>
<blockquote><p>
location /administrator {<br />
                #log_format  www_54chen_com  '$remote_addr - $remote_user [$time_local] $request '<br />
                 #               '"$status" $body_bytes_sent "$http_referer" '<br />
                  #              '"$http_user_agent" "$http_x_forwarded_for"';<br />
             # access_log  /data/www.log  www_54chen_com;<br />
            set $fuck 0;<br />
            if ($remote_addr = '1.1.1.1'){<br />
                set $fuck 1;<br />
            }<br />
            if ($remote_addr = '1.1.1.2'){<br />
                set $fuck 1;<br />
            }<br />
            if ($remote_addr = '1.1.1.3'){<br />
                set $fuck 1;<br />
            }<br />
            if ($http_x_forwarded_for = '2.2.2.2') {<br />
                set $fuck 1;<br />
            }<br />
            if ($fuck = 0){<br />
                return 404;<br />
            }<br />
         #此处还需要填写和其他location一样的以提供正常服务环境<br />
        }
</p></blockquote>
<p>1） 1.1.1.1 1.1.1.2 1.1.1.3都是直接ip地址<br />
2)  2.2.2.2是代理之前的ip地址</p>
<p>另外流行的另一种做法：</p>
<blockquote><p>            allow 1.1.1.1;<br />
            allow 1.1.1.2;<br />
            allow 1.1.1.3;<br />
            deny all;</p></blockquote>
<p>但此方法我(<a href="http://www.54chen.com">54chen</a>)始终没找到支持代理的判断。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/nginx-conf-ip-setting.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP-FPM配置sendmail支持PHP发信</title>
		<link>http://www.54chen.com/php-tech/php-fpm-configuration-sendmail.html</link>
		<comments>http://www.54chen.com/php-tech/php-fpm-configuration-sendmail.html#comments</comments>
		<pubDate>Tue, 23 Feb 2010 07:32:38 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://www.54chen.com/php-tech/php-fpm-configuration-sendmail.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>当下常用的环境CentOS+nginx+php-fpm+mysql. 之前五四陈科学院曾有一文章是介绍环境的配置的，挖一挖水，链接在这里： wordpress nginx php-cgi mysql在128m内存下的vps安装和优化手记[原创] 如果要使用mail功能，需要按如下步骤操作： 第一步、安装sendmail yum install sendmail 第二步、启动sendmail service sendmail start 第三步、设置为auto start chkconfig sendmail on 第四步、修改php-fpm.conf: 搜索sendmail，去掉那一行两头的注释如下： &#60;value name="sendmail_path"&#62;/usr/sbin/sendmail -t -i&#60;/value&#62; 第五步、php-fpm reload<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>当下常用的环境CentOS+nginx+php-fpm+mysql.</p>
<p>之前五四陈科学院曾有一文章是介绍<a href="http://www.54chen.com/uncategorized/gae-java%e6%94%af%e6%8c%81%e8%af%95%e7%94%a8%e6%89%8b%e8%ae%b0.html">环境</a>的配置的，挖一挖水，链接在这里：</p>
<p><a href="http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html">wordpress nginx php-cgi mysql在128m内存下的vps安装和优化手记[原创]</a></p>
<p>如果要使用<a href="http://www.54chen.com/flex/thousand-oaks-school-network-all-network-urgent-flash-as3-engineers-social-game-game-planning.html">mail</a>功能，需要按如下步骤操作：</p>
<p>第一步、安装sendmail</p>
<p>yum install sendmail</p>
<p>第二步、启动sendmail</p>
<p>service sendmail start</p>
<p>第三步、设置为auto start</p>
<p>chkconfig sendmail on</p>
<p>第四步、修改php-fpm.conf:</p>
<p>搜索sendmail，去掉那一行两头的注释如下：</p>
<blockquote><p>&lt;value name="sendmail_path"&gt;/usr/sbin/sendmail -t -i&lt;/value&gt;</p></blockquote>
<p>第五步、php-fpm reload </p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/php-tech/php-fpm-configuration-sendmail.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ubuntu 9.10快速安装nginx+php环境手记[54chen科学院]</title>
		<link>http://www.54chen.com/php-tech/ubuntu-910-quick-install-nginx-php-notes-from-the-environment-54.html</link>
		<comments>http://www.54chen.com/php-tech/ubuntu-910-quick-install-nginx-php-notes-from-the-environment-54.html#comments</comments>
		<pubDate>Thu, 24 Dec 2009 09:17:05 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.54chen.com/php-tech/ubuntu-910-quick-install-nginx-php-notes-from-the-environment-54.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>我(54chen)因为场景需要，特地在ubuntu9.10中安装nginx+php的环境，要快速不要优化，记录如下： sudo apt-get install php5 php5-cgi php5-cli php5-gd php5-curl php5-mysql nginx sudo apt-get install lighttpd spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php-cgi 上面的操作解读： 1.安装php nginx 2.安装lighttpd，为啥要安装这个，因为他有个spawn-fcgi，因为apt下来的php不是php-fpm。 3.用spawn-fcgi启动php-cgi在9000端口监听。 sudo vim /etc/php5/cgi/php.ini 修改php.ini文件 cgi.fix_pathinfo=1; 这样php-cgi方能正常使用SCRIPT_FILENAME这个变量 sudo &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>我(<a href="http://www.54chen.com">54chen</a>)因为场景需要，特地在<a href="http://www.54chen.com/_linux_/11-return-ubuntu-910-notes-from-the-hard-disk-installation.html">ubuntu9.10</a>中安装nginx+php的环境，要快速不要优化，记录如下：</p>
<blockquote><p>sudo apt-get install php5 php5-cgi php5-cli php5-gd php5-curl php5-mysql nginx</p>
<p>sudo apt-get install lighttpd</p>
<p>spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php-cgi</p></blockquote>
<p>上面的操作解读：</p>
<p>1.安装php nginx</p>
<p>2.安装lighttpd，为啥要安装这个，因为他有个spawn-fcgi，因为apt下来的php不是php-fpm。</p>
<p>3.用spawn-fcgi启动php-cgi在9000端口监听。</p>
<blockquote><p>sudo vim /etc/php5/cgi/php.ini</p>
<p>修改php.ini文件</p>
<p>cgi.fix_pathinfo=1; 这样php-cgi方能正常使用SCRIPT_FILENAME这个变量</p></blockquote>
<p>sudo vim /etc/nginx/sites-enabled/www.54chen.com</p>
<blockquote><p>server {<br />
listen 80; //端口<br />
server_name wiki.54chen.com; //虚拟域名<br />
access_log /var/log/nginx/hwiki.54chen.com.access.log; //访问日志<br />
location / {<br />
root /home/wiki.54chen.com; //size根目录<br />
index index.php;<br />
}<br />
location ~ \.php$ { #php fastcgi的配置<br />
fastcgi_pass 127.0.0.1:9000; #php fastcgi的代理端口与ip<br />
fastcgi_index index.php;<br />
fastcgi_param SCRIPT_FILENAME /home/wiki.54chen.com$fastcgi_script_name; #要处理的php文件的路径<br />
include /etc/nginx/fastcgi_params; #fastcgi的参数文件地址<br />
}<br />
}</p></blockquote>
<p>好，上面的操作就建立了一个<a href="http://www.54chen.com/memo/%e4%b8%80%e5%8f%a5%e8%af%9d%e8%ae%b0%e5%bd%95%e5%a4%87%e5%bf%98.html">虚拟主机</a>，保存好。</p>
<p>sudo killall apache2</p>
<p>杀掉apache，启动nginx.</p>
<p>sudo /etc/init.d/nginx start</p>
<p>大功告成！整个过程不超过十五分钟。呼呼～～</p>
<p>圣诞快乐！！！</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/php-tech/ubuntu-910-quick-install-nginx-php-notes-from-the-environment-54.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[五四陈小技巧]全站换域名时利用nginx和javascript做简单友好的换域名跳转通知</title>
		<link>http://www.54chen.com/architecture/54-chen-skills-the-whole-point-for-domain-names-using-nginx-and-javascript-to-do-a-simple-jump-to-inform-the-friendly-exchange-of-domain-names.html</link>
		<comments>http://www.54chen.com/architecture/54-chen-skills-the-whole-point-for-domain-names-using-nginx-and-javascript-to-do-a-simple-jump-to-inform-the-friendly-exchange-of-domain-names.html#comments</comments>
		<pubDate>Wed, 09 Sep 2009 08:41:21 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[架构研究]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[域名切换]]></category>

		<guid isPermaLink="false">http://www.54chen.com/architecture/54-chen-skills-the-whole-point-for-domain-names-using-nginx-and-javascript-to-do-a-simple-jump-to-inform-the-friendly-exchange-of-domain-names.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>在经过上一波的xiaonei.com转renren.com后，昨夜再次迎来新一波的kaixin-&#62;renren code的过程，期间有域名要求用新的域名，并且要老域名有跳转有提示，于是采用了下面的办法。 老域名是 old.com 新域名是 new.com 迁移挂维护的过程就略过了，直接说重点， 第一步，修改nginx.conf，删除原来old.com的定义，增加： server { listen 80; server_name old.com; location / { root   /old; if (!-e $request_filename){ rewrite ^/(.*)?$ /index.html?t=$1 last; } } } 第二步，在/old下放进一个index.html，代码如下： &#60;div class="all-error"&#62; &#60;h1&#62;&#60;span&#62;old换名啦！&#60;/span&#62; &#60;br&#62; 原来old更名为new，请放心不会影响您的使用，新的地址为&#60;a href="http://new.com" id="link"&#62;new.c om&#60;/a&#62;谢谢您的支持！ &#60;/h1&#62; &#60;p&#62; &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>在经过上一波的xiaonei.com转renren.com后，昨夜再次迎来新一波的kaixin-&gt;renren code的过程，期间有域名要求用新的域名，并且要老域名有跳转有提示，于是采用了下面的办法。</p>
<p>老域名是 old.com</p>
<p>新域名是 new.com</p>
<p>迁移挂维护的过程就略过了，直接说重点，</p>
<p>第一步，修改nginx.conf，删除原来old.com的定义，增加：</p>
<blockquote><p>server {<br />
listen 80;<br />
server_name old.com;</p>
<p>location / {<br />
root   /old;<br />
if (!-e $request_filename){<br />
rewrite ^/(.*)?$ /index.html?t=$1 last;<br />
}<br />
}<br />
}</p></blockquote>
<p>第二步，在/old下放进一个index.html，<a href="http://www.54chen.com/576-54%e9%99%88%e7%a7%91%e5%ad%a6%e9%99%a28021x%e6%ba%90%e4%bb%a3%e7%a0%81%e4%b8%8b%e8%bd%bd/">代码</a>如下：</p>
<blockquote><p>&lt;div class="all-error"&gt;</p>
<p>&lt;h1&gt;&lt;span&gt;old换名啦！&lt;/span&gt;<br />
&lt;br&gt;<br />
原来old更名为new，请放心不会影响您的使用，新的地址为&lt;a href="http://new.com" id="link"&gt;new.c<br />
om&lt;/a&gt;谢谢您的支持！<br />
&lt;/h1&gt;<br />
&lt;p&gt;<br />
2秒之后自动跳转到新的地址...<br />
&lt;/p&gt;<br />
&lt;/div&gt;</p>
<p>&lt;script type="text/javascript"&gt;<br />
document.getElementById("link").href = location.href.replace("old.com","new.com");<br />
setTimeout(function(){<br />
location.href =  location.href.replace("old.com","new.com");<br />
}, 2000)<br />
&lt;/script&gt;</p></blockquote>
<p>第三步，关机，回家睡觉</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/architecture/54-chen-skills-the-whole-point-for-domain-names-using-nginx-and-javascript-to-do-a-simple-jump-to-inform-the-friendly-exchange-of-domain-names.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to: redirect WordPress RSS feeds to feedburner with nginx[原创]</title>
		<link>http://www.54chen.com/_linux_/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original.html</link>
		<comments>http://www.54chen.com/_linux_/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original.html#comments</comments>
		<pubDate>Sat, 15 Aug 2009 14:01:49 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[feedburner]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>[转载请注明：http://www.54chen.com/727-how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original/ 作者：陈臻] 可能有大多数朋友都会在用wordpress的时候需要从原始的feed地址转到feedburner上，看到一个老外的博客上说了apache的htaccess的修改方案： &#60;IfModule mod_rewrite.c&#62; RewriteEngine on RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC] RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC] RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/-aboutJavaAndPhp [R=302,NC,L] &#60;/IfModule&#62; 心想这nginx也不能没个着落下，于是就试验了一下，nginx作如下修改即可： if ($http_user_agent !~ FeedBurner) {   rewrite ^/feed$ http://feeds.feedburner.com/-aboutJavaAndPhp redirect;   rewrite ^/feed/$ http://feeds.feedburner.com/-aboutJavaAndPhp redirect; } 都是302跳，可能对seo不是太好，不过可能是对一些rss客户端比较好。<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>[转载请注明：<a href="http://www.54chen.com/727-how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original/">http://www.54chen.com/727-how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original/</a> 作者：陈臻]</p>
<p>可能有大多数朋友都会在用wordpress的时候需要从原始的feed地址转到feedburner上，看到一个老外的博客上说了apache的htaccess的修改方案：</p>
<blockquote><p>&lt;IfModule mod_rewrite.c&gt;<br />
RewriteEngine on<br />
RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC]<br />
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]<br />
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ <a href="http://feeds.feedburner.com/-aboutJavaAndPhp">http://feeds.feedburner.com/-aboutJavaAndPhp</a> [R=302,NC,L]<br />
&lt;/IfModule&gt;</p></blockquote>
<p>心想这nginx也不能没个着落下，于是就试验了一下，nginx作如下修改即可：</p>
<blockquote><p>if ($http_user_agent !~ FeedBurner) {<br />
  rewrite ^/feed$ <a href="http://feeds.feedburner.com/-aboutJavaAndPhp">http://feeds.feedburner.com/-aboutJavaAndPhp</a> redirect;<br />
  rewrite ^/feed/$ <a href="http://feeds.feedburner.com/-aboutJavaAndPhp">http://feeds.feedburner.com/-aboutJavaAndPhp</a> redirect;<br />
}</p></blockquote>
<p>都是302跳，可能对seo不是太好，不过可能是对一些rss客户端比较好。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress nginx php-cgi mysql在128m内存下的vps安装和优化手记[原创]</title>
		<link>http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html</link>
		<comments>http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html#comments</comments>
		<pubDate>Sun, 02 Aug 2009 07:34:49 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[架构研究]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-cgi]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>[ 文章作者：陈臻 本文版本：v1.0 最后修改：2009.8.2 转载请注明原文链接：http://www.54chen.com/688-wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes/ ] 选取CentOS，因为它是号称最安全及性能都相对较好的Linux系统。系统内存128m，系统用掉30m，有100m左右可用（如图1所示），swap已经有256M，硬盘为5G，除去系统后大约有4G可供捣腾。 图1。   首先，在空白的系统上使用下面的命令，安装gcc等一堆工具和后面php会用到的一些包： yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>[ 文章作者：陈臻 本文版本：v1.0 最后修改：2009.8.2 转载请注明原文链接：<a href="http://www.54chen.com/688-wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes/">http://www.54chen.com/688-wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes/</a> ]</p>
<p>选取CentOS，因为它是号称最安全及性能都相对较好的Linux系统。系统内存128m，系统用掉30m，有100m左右可用（如图1所示），swap已经有256M，硬盘为5G，除去系统后大约有4G可供捣腾。</p>
<p><a href="http://www.54chen.com/wp-content/uploads/2009/08/1.jpg"><img class="alignleft size-full wp-image-689" title="图1" src="http://www.54chen.com/wp-content/uploads/2009/08/1.jpg" alt="" width="500" height="78" /></a><br />
图1。</p>
<p> </p>
<p>首先，在空白的系统上使用下面的命令，安装gcc等一堆工具和后面php会用到的一些包：</p>
<p><code>yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers</code></p>
<p>yum这一堆东西会有点慢，这里正好插播一下，mysql的编译在128的内存下非常慢，所以呆会儿我们会采取直接yum，php、nginx都下源码编译，经过以往的经验eAccelerator、Xcache和Zend Optimizer这三者，最好是用eAccelerator搭配Zend Optimizer能给php加速得到最佳效果，当然了，Zend Optimizer需要Zend Guard来搭配，而后者是收费的，伟大的中国人有伟大的破解。</p>
<p>我执行的时候耗时32分钟左右。</p>
<p>言归正传，继续：<br />
<code>wget http://sysoev.ru/nginx/nginx-0.7.61.tar.gz<br />
wget http://www.php.net/get/php-5.2.10.tar.gz/from/this/mirror<br />
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.10-fpm-0.5.11.diff.gz<br />
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2<br />
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz [nginx rewrite使用]</code></p>
<p>【安装<a href="http://www.54chen.com/19-mysql%e6%93%8d%e4%bd%9c%e8%a6%81%e7%82%b9%e6%95%b4%e7%90%86/">MySQL</a>】<br />
<code>yum install -y mysql-server<br />
启动MySQL:<br />
service mysqld start<br />
设置mysql数据库root帐号密码:<br />
mysqladmin -u root password 'newpassword' [引号内填密码]<br />
让mysql更安全：<br />
mysql -u root -p [此时会要求你输入刚刚设置的密码，输入后回车即可]</code></p>
<p>mysql&gt; DROP DATABASE test; [删除test数据库]<br />
mysql&gt; DELETE FROM mysql.user WHERE user = ''; [删除匿名帐户]<br />
mysql&gt;DELETE FROM mysql.user WHERE password = '';[删除无密码帐户]<br />
mysql&gt; FLUSH PRIVILEGES; [重载权限]</p>
<p>【优化MySQL】<br />
此时的mysql直接吃掉20m左右的内存，如图2所示。我们要对其进行优化，关掉<a href="http://www.54chen.com/358-mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh/">innodb</a>。</p>
<p><a href="http://www.54chen.com/wp-content/uploads/2009/08/2.jpg"><img class="alignleft size-full wp-image-691" title="图2" src="http://www.54chen.com/wp-content/uploads/2009/08/2.jpg" alt="" width="499" height="170" /></a>图2。</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>vi /etc/my.cnf<br />
在后面增加如下内容：</p>
<p><code>skip-innodb<br />
[mysql]<br />
no-auto-rehash</code></p>
<p>[mysqld]<br />
user = mysql<br />
port = 3306<br />
open_files_limit = 600<br />
back_log = 20<br />
max_connections = 100<br />
max_connect_errors = 200<br />
table_cache = 60<br />
external-locking = FALSE<br />
max_allowed_packet = 16M<br />
sort_buffer_size = 128K<br />
join_buffer_size = 128K<br />
thread_cache_size = 10<br />
thread_concurrency = 8<br />
query_cache_size = 0M<br />
query_cache_limit = 2M<br />
query_cache_min_res_unit = 2k<br />
default_table_type = MyISAM<br />
thread_stack = 192K<br />
transaction_isolation = READ-UNCOMMITTED<br />
tmp_table_size = 512K<br />
max_heap_table_size = 32M<br />
long_query_time = 1<br />
log_long_format<br />
server-id = 1<br />
binlog_cache_size = 2M<br />
max_binlog_cache_size = 4M<br />
max_binlog_size = 512M<br />
expire_logs_days = 7<br />
key_buffer_size = 4M<br />
read_buffer_size = 1M<br />
read_rnd_buffer_size = 2M<br />
bulk_insert_buffer_size = 2M<br />
myisam_sort_buffer_size = 4M<br />
myisam_max_sort_file_size = 10G<br />
myisam_max_extra_sort_file_size = 10G<br />
myisam_repair_threads = 1<br />
myisam_recover</p>
<p>[mysqldump]<br />
quick<br />
max_allowed_packet = 16M</p>
<p>【重启MySQL】<br />
service mysqld restart<br />
再看mysql吃掉的内存，已经降低了四分之一，如图3所示：<br />
<a href="http://www.54chen.com/wp-content/uploads/2009/08/3.jpg"><img class="alignleft size-full wp-image-692" title="图3" src="http://www.54chen.com/wp-content/uploads/2009/08/3.jpg" alt="" width="500" height="170" /></a>图3。</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>【安装php】<br />
首先使用yum安装上mysql的开发包，供<a href="http://www.54chen.com/490-%e5%a6%82%e4%bd%95%e7%94%a8php%e4%bb%a3%e7%a0%81%e6%b8%85%e7%a9%basquid%e7%bc%93%e5%ad%98%e4%b8%8b%e7%9a%84%e6%8c%87%e5%ae%9a%e6%96%87%e4%bb%b6/">php</a>扩展mysql使用：<br />
<code>yum -y install mysql-devel<br />
安装patch工具：<br />
yum -y install patch<br />
tar zxvf php-5.2.10.tar.gz<br />
gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1<br />
cd php-5.2.10<br />
./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysql=/usr/share/mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --without-pear<br />
make &amp;&amp; make install</code><br />
把pear手动装上(这个是5.2.10的一个bug，后面可能已经打补丁了)：<br />
curl http://pear.php.net/go-pear | /opt/php/bin/php<br />
cp php.ini-dist /opt/php/etc/php.ini</p>
<p>【安装eaccelerator】<br />
<code>tar jxvf eaccelerator-0.9.5.3.tar.bz2<br />
cd eaccelerator-0.9.5.3<br />
/opt/php/bin/phpize<br />
./configure --enable-eaccelerator=shared --with-php-config=/opt/php/bin/php-config<br />
make &amp;&amp; make install</code><br />
mkdir -p /opt/eaccelerator_cache<br />
vi /opt/php/etc/php.ini</p>
<p>添加下面的内容：<br />
<code>[eaccelerator]<br />
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"<br />
eaccelerator.shm_size="64"<br />
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"<br />
eaccelerator.enable="1"<br />
eaccelerator.optimizer="1"<br />
eaccelerator.check_mtime="1"<br />
eaccelerator.debug="0"<br />
eaccelerator.filter=""<br />
eaccelerator.shm_max="0"<br />
eaccelerator.shm_ttl="3600"<br />
eaccelerator.shm_prune_period="3600"<br />
eaccelerator.shm_only="0"<br />
eaccelerator.compress="1"<br />
eaccelerator.compress_level="9"</code></p>
<p> </p>
<p>【安装<a href="http://www.54chen.com/157-php%e4%bb%a3%e7%a0%81%e7%9a%84%e4%bc%98%e4%b8%8e%e5%8a%a3/">Zend</a> Optimizer】<br />
要去zend.com上注册用户名后进download页面下载，这里太弱智了，不知道zend是否有专门的产品人员，这种注册下载有什么意义，只是一堆死账号而已。<br />
下载ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz<br />
<code>tar -zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz<br />
cd ZendOptimizer-3.3.3-linux-glibc23-i386<br />
./install</code></p>
<p>运行过程中会要求你写些安装路径啥的，照着写就是。<br />
如果出现类似下面的错误：<br />
./install-tty: line 139: ./php: cannot execute binary file<br />
那说明你下错了包了，这种情况是因为你32位的系统下了64位的包或者是反过来。</p>
<p>【安装nginx】<br />
<code>tar -zxvf pcre-7.9.tar.gz<br />
cd pcre-7.9<br />
./configure<br />
make &amp;&amp; make install<br />
cd ..</code></p>
<p>tar zxvf nginx-0.7.61.tar.gz<br />
cd nginx-0.7.61<br />
./configure --user=www --group=www --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module<br />
make &amp;&amp; make install</p>
<p>增加www用户：<br />
groupadd www<br />
useradd -g www www</p>
<p>【优化php\nginx】<br />
1.优化php-fpm.conf<br />
<code>vi /opt/php/etc/php-fpm.conf<br />
修改log level为error:<br />
error<br />
修改max_children:<br />
5<br />
修改listen_address为unix socket方式运行：<br />
/tmp/php-cgi.sock</code></p>
<p>2.优化nginx.conf<br />
vi /opt/nginx/conf/nginx.conf<br />
在events中增加：<br />
<code>use epoll;<br />
在http中增加下面的代码，打开gzip：<br />
gzip on;<br />
gzip_min_length 1k;<br />
gzip_buffers 4 16k;<br />
gzip_http_version 1.0;<br />
gzip_comp_level 2;<br />
gzip_types text/plain application/x-javascript text/css application/xml;<br />
gzip_vary on;<br />
在使用php的server中使用unix socket通信方式：<br />
fastcgi_pass unix:/tmp/php-cgi.sock;</code></p>
<p>【设置开机启动】<br />
/sbin/chkconfig --add mysqld [在服务清单中添加mysql服务]<br />
/sbin/chkconfig mysqld on [设置mysql服务开机启动]</p>
<p>vi /etc/rc.locale<br />
加入两行：<br />
/opt/php/sbin/php-fpm start<br />
/opt/nginx/sbin/nginx</p>
<p>【误区提示】<br />
XEN更像物理服务器，会尽量把剩余的内存当成buffer和cache，所以看到下图的时候不要惊慌，其实内存都在cache里了。<br />
<a href="http://www.54chen.com/wp-content/uploads/2009/08/x.jpg"><img class="alignleft size-full wp-image-693" title="图4" src="http://www.54chen.com/wp-content/uploads/2009/08/x.jpg" alt="" width="500" height="94" /></a>图4</p>
<p> </p>
<p> </p>
<p>【wordpress专项优化】<br />
使用wp-super-cache插件，将页面生成html，省去php的开销，性能有提升。<br />
对照access log，刷新页面，看堵在什么地方</p>
<p>【几个建议】<br />
合并css js个数 并且压缩 速度提升明显<br />
wordpress没有任何插件的时候，效率是很不错的，但是有些不负责任的插件会导致整体看起来很慢，下面是一些常用的插件的问题：<br />
1.twitter tools插件：用来从后端取twitter数据的，这个插件搞了一个js一个css在head里，并且都是通过php生成的，两个php请求，让首页很慢。建议去掉（可能会影响自动化？没来得及分析细节）。<br />
2.wp-spamfree插件：用来做antispam的，这是一个动态生成的js，不知道为什么非常慢。建议换别的插件。</p>
<p>【结果展示】<br />
在完成上述一系列的操作后，http://54chen.com 我是陈科学院的打开速度已经非常迅速了，基本上一秒钟就能全部显示。内存还有40m空闲，如图5所示：<br />
<a href="http://www.54chen.com/wp-content/uploads/2009/08/5.jpg"><img class="alignleft size-full wp-image-694" title="图5" src="http://www.54chen.com/wp-content/uploads/2009/08/5.jpg" alt="" width="500" height="79" /></a>图5</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html/feed</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
	</channel>
</rss>

