<?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>iCodex&#039;s Blog &#187; nginx</title>
	<atom:link href="http://icodex.org/tag/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>http://icodex.org</link>
	<description>诡谲</description>
	<lastBuildDate>Fri, 13 Jan 2012 13:50:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>[更新]适用于Directadmin面板的Nginx自动安装脚本</title>
		<link>http://icodex.org/2010/05/directadmin-nginx-automated-installer/</link>
		<comments>http://icodex.org/2010/05/directadmin-nginx-automated-installer/#comments</comments>
		<pubDate>Fri, 21 May 2010 04:17:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[codex]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[DirectAdmin]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://icodex.org/?p=663</guid>
		<description><![CDATA[个人比较偏爱apache,但apache也有不足的地方.比如处理静态请求上.apache会很费劲.nginx也是比较喜欢的一个轻型http服务器.但nginx用fast-cgi跑php也有不足.所以我做了组合,前端跑nginx,后端跑apache.运行了一段时间之后.发现真的不错.所以就一直推荐周遭的朋友这样用.这些日子折腾了好久.终于完成了在Directadmin面板基础上安装nginx的自动安装脚本.这次更新的与前段时间发布的教程不同.这次将nginx真正放到了前端.静态资源完全由nginx处理.后端的apache处理的请求仅限于动态.真正做到动静分离.这样就可以负载更多的访问了. 安装我写了一个脚本.下载后执行就可以了(仅限于centos系统).但是有一个前提:必须在全新安装directadmin面板的机器上安装,这是个已知问题. 安装方法: wget http://icodex.org/dl/directadmin/install.sh chmod 755 install.sh ./install.sh 卸载方法: wget http://icodex.org/dl/directadmin/uninstall.sh chmod 755 uninstall.sh ./uninstall.sh 更新DA版本后: wget http://icodex.org/dl/directadmin/reconfigure.shchmod 755 reconfigure.sh./reconfigure.sh 如果有任何建议或疑问,请发邮件给我(admin@evlit.com) 谢谢! 有朋友说安装之后无法使用备份.为此我亲自测试没有发现问题.如果出现权限问题,请管理员检查用户文件系统权限. Related Posts给DirectAdmin面板增加nginx前端 (3)[更新]搭建前后端web生产环境 (21)[更新]nginx 自动安装脚本 For cPanel (62)适用于 CentOS 5系列的 Virt-manager 0.8.6 RPM下载 (2)Google推出apache加速模块mod_pagespeed (1)]]></description>
			<content:encoded><![CDATA[<p>个人比较偏爱apache,但apache也有不足的地方.比如处理静态请求上.apache会很费劲.nginx也是比较喜欢的一个轻型http服务器.但nginx用fast-cgi跑php也有不足.所以我做了组合,前端跑nginx,后端跑apache.运行了一段时间之后.发现真的不错.所以就一直推荐周遭的朋友这样用.这些日子折腾了好久.终于完成了在Directadmin面板基础上安装nginx的自动安装脚本.这次更新的与前段时间发布的<a href="http://icodex.org/2010/05/%e7%bb%99directadmin%e9%9d%a2%e6%9d%bf%e5%a2%9e%e5%8a%a0nginx%e5%89%8d%e7%ab%af/">教程</a>不同.这次将nginx真正放到了前端.静态资源完全由nginx处理.后端的apache处理的请求仅限于动态.真正做到动静分离.这样就可以负载更多的访问了.</p>
<p>安装我写了一个脚本.下载后执行就可以了(<span style="color: #ff0000;">仅限于centos系统</span>).但是有一个前提:<span style="color: #ff0000;">必须在全新安装directadmin面板的机器上安装</span>,这是个已知问题.</p>
<p>安装方法:<span id="more-663"></span></p>
<p><code>wget http://icodex.org/dl/<a href="http://icodex.org/tag/directadmin/" class="st_tag internal_tag" rel="tag" title="Posts tagged with DirectAdmin">directadmin</a>/install.sh<br /> chmod <span style="color: #ff0000;">755</span> install.sh<br /> ./install.sh</code></p>
<p>卸载方法:</p>
<p><code>wget http://icodex.org/dl/directadmin/uninstall.sh<br /> chmod <span style="color: #ff0000;">755</span> uninstall.sh<br /> ./uninstall.sh</code></p>
<p>更新DA版本后:</p>
<p>wget http://icodex.org/dl/directadmin/reconfigure.sh<br />chmod 755 reconfigure.sh<br />./reconfigure.sh</p>
<p>如果有任何建议或疑问,请发邮件给我(admin@evlit.com) 谢谢!</p>
<p>有朋友说安装之后无法使用备份.为此我亲自测试没有发现问题.如果出现权限问题,请管理员检查用户文件系统权限.</p>
<p><a href="http://www.icodex.org/wp-content/uploads/2010/05/1.png?e97550"><img class="aligncenter size-medium wp-image-824" title="1" src="http://www.icodex.org/wp-content/uploads/2010/05/1-500x411.png?e97550" alt="" width="500" height="411" /></a></p>

<a href='http://icodex.org/2010/05/directadmin-nginx-automated-installer/1-3/' title='1'><img width="150" height="150" src="http://www.icodex.org/wp-content/uploads/2010/05/1-150x150.png?e97550" class="attachment-thumbnail" alt="1" title="1" /></a>
<a href='http://icodex.org/2010/05/directadmin-nginx-automated-installer/2-3/' title='2'><img width="150" height="150" src="http://www.icodex.org/wp-content/uploads/2010/05/2-150x150.png?e97550" class="attachment-thumbnail" alt="2" title="2" /></a>
<a href='http://icodex.org/2010/05/directadmin-nginx-automated-installer/3-3/' title='3'><img width="150" height="150" src="http://www.icodex.org/wp-content/uploads/2010/05/3-150x150.png?e97550" class="attachment-thumbnail" alt="3" title="3" /></a>
<a href='http://icodex.org/2010/05/directadmin-nginx-automated-installer/4-3/' title='4'><img width="150" height="150" src="http://www.icodex.org/wp-content/uploads/2010/05/4-150x150.png?e97550" class="attachment-thumbnail" alt="4" title="4" /></a>
<a href='http://icodex.org/2010/05/directadmin-nginx-automated-installer/5-2/' title='5'><img width="150" height="150" src="http://www.icodex.org/wp-content/uploads/2010/05/5-150x150.png?e97550" class="attachment-thumbnail" alt="5" title="5" /></a>
<a href='http://icodex.org/2010/05/directadmin-nginx-automated-installer/6-2/' title='6'><img width="150" height="150" src="http://www.icodex.org/wp-content/uploads/2010/05/6-150x150.png?e97550" class="attachment-thumbnail" alt="6" title="6" /></a>
<a href='http://icodex.org/2010/05/directadmin-nginx-automated-installer/7-2/' title='7'><img width="150" height="150" src="http://www.icodex.org/wp-content/uploads/2010/05/7-150x150.png?e97550" class="attachment-thumbnail" alt="7" title="7" /></a>

<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://icodex.org/2010/05/%e7%bb%99directadmin%e9%9d%a2%e6%9d%bf%e5%a2%9e%e5%8a%a0nginx%e5%89%8d%e7%ab%af/" title="给DirectAdmin面板增加nginx前端">给DirectAdmin面板增加nginx前端</a> (3)</li><li><a href="http://icodex.org/2010/03/nginx-apache-guide/" title="[更新]搭建前后端web生产环境">[更新]搭建前后端web生产环境</a> (21)</li><li><a href="http://icodex.org/2010/02/nginx%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac-for-cpanel/" title="[更新]nginx 自动安装脚本 For cPanel">[更新]nginx 自动安装脚本 For cPanel</a> (62)</li><li><a href="http://icodex.org/2011/06/%e9%80%82%e7%94%a8%e4%ba%8e-centos-5%e7%b3%bb%e5%88%97%e7%9a%84-virt-manager-0-8-6-rpm%e4%b8%8b%e8%bd%bd/" title="适用于 CentOS 5系列的 Virt-manager 0.8.6 RPM下载">适用于 CentOS 5系列的 Virt-manager 0.8.6 RPM下载</a> (2)</li><li><a href="http://icodex.org/2010/11/google%e6%8e%a8%e5%87%baapache%e5%8a%a0%e9%80%9f%e6%a8%a1%e5%9d%97mod_pagespeed/" title="Google推出apache加速模块mod_pagespeed">Google推出apache加速模块mod_pagespeed</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://icodex.org/2010/05/directadmin-nginx-automated-installer/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
		<item>
		<title>nginx文件类型错误解析漏洞</title>
		<link>http://icodex.org/2010/05/nginx-0day-by-80sec/</link>
		<comments>http://icodex.org/2010/05/nginx-0day-by-80sec/#comments</comments>
		<pubDate>Fri, 21 May 2010 01:23:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[codex]]></category>
		<category><![CDATA[0day]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://icodex.org/?p=658</guid>
		<description><![CDATA[漏洞介绍：nginx是一款高性能的web服务器，使用非常广泛，其不仅经常被用作反向代理，也可以非常好的支持PHP的运行。80sec发现 其中存在一个较为严重的安全问题，默认情况下可能导致服务器错误的将任何类型的文件以PHP的方式进行解析，这将导致严重的安全问题，使得恶意的攻击者可 能攻陷支持php的nginx服务器。 漏洞分析：nginx默认以cgi的方式支持php的运行，譬如在配置文件当中可以 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } 的方式支持对php的解析，location对请求进行选择的时候会使用URI环境变量进行选择，其中传递到后端Fastcgi的关键变量 SCRIPT_FILENAME由nginx生成的$fastcgi_script_name决定，而通过分析可以看 到$fastcgi_script_name是直接由URI环境变量控制的，这里就是产生问题的点。而为了较好的支持PATH_INFO的提取，在PHP 的配置选项里存在cgi.fix_pathinfo选项，其目的是为了从SCRIPT_FILENAME里取出真正的脚本名。 那么假设存在一个http://www.80sec.com/80sec.jpg，我们以如下的方式去访问 http://www.80sec.com/80sec.jpg/80sec.php 将会得到一个URI /80sec.jpg/80sec.php 经过location指令，该请求将会交给后端的fastcgi处理，nginx为其设置环境变量SCRIPT_FILENAME，内容为 /scripts/80sec.jpg/80sec.php 而在其他的webserver如lighttpd当中，我们发现其中的SCRIPT_FILENAME被正确的设置为 /scripts/80sec.jpg 所以不存在此问题。 后端的fastcgi在接受到该选项时，会根据fix_pathinfo配置决定是否对SCRIPT_FILENAME进行额外的处理，一般情况下如果不 对fix_pathinfo进行设置将影响使用PATH_INFO进行路由选择的应用，所以该选项一般配置开启。Php通过该选项之后将查找其中真正的脚 本文件名字，查找的方式也是查看文件是否存在，这个时候将分离出SCRIPT_FILENAME和PATH_INFO分别为 /scripts/80sec.jpg和80sec.php 最后，以/scripts/80sec.jpg作为此次请求需要执行的脚本，攻击者就可以实现让nginx以php来解析任何类型的文件了。 POC：访问一个nginx来支持php的站点，在一个任何资源的文件如robots.txt后面加上/80sec.php，这个时候你可以看到如下的区别： 访问http://www.80sec.com/robots.txt HTTP/1.1 200 OK Server: nginx/0.6.32 Date: Thu, 20 May 2010 10:05:30 GMT Content-Type: text/plain Content-Length: [...]]]></description>
			<content:encoded><![CDATA[<p>漏洞介绍：nginx是一款高性能的web服务器，使用非常广泛，其不仅经常被用作反向代理，也可以非常好的支持PHP的运行。80sec发现 其中存在一个较为严重的安全问题，默认情况下可能导致服务器错误的将任何类型的文件以PHP的方式进行解析，这将导致严重的安全问题，使得恶意的攻击者可 能攻陷支持php的nginx服务器。</p>
<p>漏洞分析：nginx默认以cgi的方式支持php的运行，譬如在配置文件当中可以</p>
<p><code>location ~ \.php$ {<br />
root           html;<br />
fastcgi_pass   127.0.0.1:9000;<br />
fastcgi_index  index.php;<br />
fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;<br />
include        fastcgi_params;<br />
}</code></p>
<p>的方式支持对php的解析，location对请求进行选择的时候会使用URI环境变量进行选择，其中传递到后端Fastcgi的关键变量 SCRIPT_FILENAME由nginx生成的$fastcgi_script_name决定，而通过分析可以看 到$fastcgi_script_name是直接由URI环境变量控制的，这里就是产生问题的点。而为了较好的支持PATH_INFO的提取，在PHP 的配置选项里存在cgi.fix_pathinfo选项，其目的是为了从SCRIPT_FILENAME里取出真正的脚本名。<span id="more-658"></span></p>
<p>那么假设存在一个http://www.80sec.com/80sec.jpg，我们以如下的方式去访问 http://www.80sec.com/80sec.jpg/80sec.php 将会得到一个URI</p>
<p><code>/80sec.jpg/80sec.php</code></p>
<p>经过location指令，该请求将会交给后端的fastcgi处理，nginx为其设置环境变量SCRIPT_FILENAME，内容为</p>
<p><code>/scripts/80sec.jpg/80sec.php</code></p>
<p>而在其他的webserver如lighttpd当中，我们发现其中的SCRIPT_FILENAME被正确的设置为</p>
<p><code>/scripts/80sec.jpg</code></p>
<p>所以不存在此问题。</p>
<p>后端的fastcgi在接受到该选项时，会根据fix_pathinfo配置决定是否对SCRIPT_FILENAME进行额外的处理，一般情况下如果不 对fix_pathinfo进行设置将影响使用PATH_INFO进行路由选择的应用，所以该选项一般配置开启。Php通过该选项之后将查找其中真正的脚 本文件名字，查找的方式也是查看文件是否存在，这个时候将分离出SCRIPT_FILENAME和PATH_INFO分别为</p>
<p><code>/scripts/80sec.jpg和80sec.php</code></p>
<p>最后，以/scripts/80sec.jpg作为此次请求需要执行的脚本，攻击者就可以实现让nginx以php来解析任何类型的文件了。</p>
<p>POC：访问一个nginx来支持php的站点，在一个任何资源的文件如robots.txt后面加上/80sec.php，这个时候你可以看到如下的区别：</p>
<p>访问http://www.80sec.com/robots.txt</p>
<p><code>HTTP/1.1 200 OK<br />
Server: <a href="http://icodex.org/tag/nginx/" class="st_tag internal_tag" rel="tag" title="Posts tagged with nginx">nginx</a>/0.6.32<br />
Date: Thu, 20 May 2010 10:05:30 GMT<br />
Content-Type: text/plain<br />
Content-Length: 18<br />
Last-Modified: Thu, 20 May 2010 06:26:34 GMT<br />
Connection: keep-alive<br />
Keep-Alive: timeout=20<br />
Accept-Ranges: bytes</code></p>
<p>访问访问http://www.80sec.com/robots.txt/80sec.php</p>
<p><code>HTTP/1.1 200 OK<br />
Server: nginx/0.6.32<br />
Date: Thu, 20 May 2010 10:06:49 GMT<br />
Content-Type: text/html<br />
Transfer-Encoding: chunked<br />
Connection: keep-alive<br />
Keep-Alive: timeout=20<br />
X-Powered-By: PHP/5.2.6</code></p>
<p>其中的Content-Type的变化说明了后端负责解析的变化，该站点就可能存在漏洞。</p>
<p>漏洞厂商：http://www.nginx.org</p>
<p>解决方案：</p>
<p>我们已经尝试联系官方，但是此前你可以通过以下的方式来减少损失</p>
<p><code>关闭cgi.fix_pathinfo为0</code></p>
<p>或者</p>
<p><code>if  ( $fastcgi_script_name ~ \..*\/.*php )  {<br />
return 403;<br />
}</code></p>
<p>PS: 鸣谢<a href="http://www.laruence.com/2010/05/20/1495.html">laruence</a>大 牛在分析过程中给的帮助</p>
<p>转载自: nginx文件类型错误解析漏洞:http://www.80sec.com/nginx-securit.html</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://icodex.org/2010/05/directadmin-nginx-automated-installer/" title="[更新]适用于Directadmin面板的Nginx自动安装脚本">[更新]适用于Directadmin面板的Nginx自动安装脚本</a> (55)</li><li><a href="http://icodex.org/2010/05/%e7%bb%99directadmin%e9%9d%a2%e6%9d%bf%e5%a2%9e%e5%8a%a0nginx%e5%89%8d%e7%ab%af/" title="给DirectAdmin面板增加nginx前端">给DirectAdmin面板增加nginx前端</a> (3)</li><li><a href="http://icodex.org/2010/03/nginx-apache-guide/" title="[更新]搭建前后端web生产环境">[更新]搭建前后端web生产环境</a> (21)</li><li><a href="http://icodex.org/2010/02/nginx%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac-for-cpanel/" title="[更新]nginx 自动安装脚本 For cPanel">[更新]nginx 自动安装脚本 For cPanel</a> (62)</li><li><a href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/" title="为nginx虚拟主机配置startssl免费https证书">为nginx虚拟主机配置startssl免费https证书</a> (5)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://icodex.org/2010/05/nginx-0day-by-80sec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>给DirectAdmin面板增加nginx前端</title>
		<link>http://icodex.org/2010/05/%e7%bb%99directadmin%e9%9d%a2%e6%9d%bf%e5%a2%9e%e5%8a%a0nginx%e5%89%8d%e7%ab%af/</link>
		<comments>http://icodex.org/2010/05/%e7%bb%99directadmin%e9%9d%a2%e6%9d%bf%e5%a2%9e%e5%8a%a0nginx%e5%89%8d%e7%ab%af/#comments</comments>
		<pubDate>Tue, 11 May 2010 04:13:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[codex]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[DirectAdmin]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://icodex.org/?p=626</guid>
		<description><![CDATA[已更新自动安装版本 : http://icodex.org/2010/05/directadmin-nginx-automated-installer/ Related Posts[更新]适用于Directadmin面板的Nginx自动安装脚本 (55)[更新]搭建前后端web生产环境 (21)[更新]nginx 自动安装脚本 For cPanel (62)Google推出apache加速模块mod_pagespeed (1)nginx文件类型错误解析漏洞 (0)]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">已更新自动安装版本</span> : <a href="http://icodex.org/2010/05/directadmin-nginx-automated-installer/">http://icodex.org/2010/05/directadmin-nginx-automated-installer/</a></p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://icodex.org/2010/05/directadmin-nginx-automated-installer/" title="[更新]适用于Directadmin面板的Nginx自动安装脚本">[更新]适用于Directadmin面板的Nginx自动安装脚本</a> (55)</li><li><a href="http://icodex.org/2010/03/nginx-apache-guide/" title="[更新]搭建前后端web生产环境">[更新]搭建前后端web生产环境</a> (21)</li><li><a href="http://icodex.org/2010/02/nginx%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac-for-cpanel/" title="[更新]nginx 自动安装脚本 For cPanel">[更新]nginx 自动安装脚本 For cPanel</a> (62)</li><li><a href="http://icodex.org/2010/11/google%e6%8e%a8%e5%87%baapache%e5%8a%a0%e9%80%9f%e6%a8%a1%e5%9d%97mod_pagespeed/" title="Google推出apache加速模块mod_pagespeed">Google推出apache加速模块mod_pagespeed</a> (1)</li><li><a href="http://icodex.org/2010/05/nginx-0day-by-80sec/" title="nginx文件类型错误解析漏洞">nginx文件类型错误解析漏洞</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://icodex.org/2010/05/%e7%bb%99directadmin%e9%9d%a2%e6%9d%bf%e5%a2%9e%e5%8a%a0nginx%e5%89%8d%e7%ab%af/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>[更新]搭建前后端web生产环境</title>
		<link>http://icodex.org/2010/03/nginx-apache-guide/</link>
		<comments>http://icodex.org/2010/03/nginx-apache-guide/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 06:55:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[codex]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[pure-ftpd]]></category>

		<guid isPermaLink="false">http://icodex.org/?p=334</guid>
		<description><![CDATA[前言:谈到Linux下的web生产环境,大家就会想到apache这个开源服务器软件.apache可以整合大多数应用,比如jsp,php,cgi,python等等,但是apache过于臃肿以及对静态文件响应过于缓慢让很多使用者感到头疼.而nginx作为新崛起的服务器软件,在很多方面超出apache,定位也很明确:高性能的 HTTP 和反向代理服务器.因而,本篇主要讲的是nginx作为前端,apache作为后端的应用环境搭建过程. 为什么不使用nginx+php(fastcgi)作为生产环境? php(fastcgi)不够稳定,容易出现50x错误,在生成相对复杂的页面时没有优势,长时间占用也会使php-cgi进程死去. 在安全性,多用户多站点的权限问题比较严重.php(fastcgi)在应对多用户多站点往往捉襟见肘,不易于实施. 整合其他语言,apache表现得游刃有余.资源利用恰到好处. 为什么采用nginx做前端,apache作为后端的方案?nginx在处理静态内容上较apache是几倍或几十倍的差异,因而放在前面过滤静态内容是最为恰当的.同时nginx也是一个负载均衡器,低资源消耗,高性能转发是它的特点.经过nginx在前面的过滤,后端的apache需要处理的内容相对就比较少了.只需负责处理动态内容就可以了.在性能与稳定性的权衡下,使用nginx+apache搭配会让它们在各自擅长的领域展现自身的价值. 本教程以CentOS 5.4 32bit为环境.其他Linux发行版本暂未测试.nginx,php,apache,mysql,pureftpd均为最新稳定版. 获取操作系统源更新. yum update yum -y install gcc gcc-c++ bison patch unzip mlocate flex wget automake autoconf gd cpp gettext readline-devel 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 libidn libidn-devel [...]]]></description>
			<content:encoded><![CDATA[<p><strong>前言</strong>:谈到Linux下的web生产环境,大家就会想到apache这个开源服务器软件.apache可以整合大多数应用,比如jsp,php,cgi,python等等,但是apache过于臃肿以及对静态文件响应过于缓慢让很多使用者感到头疼.而nginx作为新崛起的服务器软件,在很多方面超出apache,定位也很明确:高性能的 HTTP 和反向代理服务器.因而,本篇主要讲的是nginx作为前端,apache作为后端的应用环境搭建过程.</p>
<p><strong>为什么<span style="color: #ff0000;">不</span></strong>使用nginx+php(fastcgi)作为生产环境?</p>
<ol>
<li>php(fastcgi)不够稳定,容易出现50x错误,在生成相对复杂的页面时没有优势,长时间占用也会使php-cgi进程死去.</li>
<li>在安全性,多用户多站点的权限问题比较严重.php(fastcgi)在应对多用户多站点往往捉襟见肘,不易于实施.</li>
<li>整合其他语言,apache表现得游刃有余.资源利用恰到好处.</li>
</ol>
<p>为什么采用nginx做前端,apache作为后端的方案?nginx在处理静态内容上较apache是几倍或几十倍的差异,因而放在前面过滤静态内容是最为恰当的.同时nginx也是一个负载均衡器,低资源消耗,高性能转发是它的特点.经过nginx在前面的过滤,后端的apache需要处理的内容相对就比较少了.只需负责处理动态内容就可以了.在性能与稳定性的权衡下,使用nginx+apache搭配会让它们在各自擅长的领域展现自身的价值.</p>
<p>本教程以<span style="color: #ff0000;"><a href="http://icodex.org/tag/centos/" class="st_tag internal_tag" rel="tag" title="Posts tagged with CentOS">CentOS</a> 5.4 32bit</span>为环境.其他Linux发行版本暂未测试.<a href="http://icodex.org/tag/nginx/" class="st_tag internal_tag" rel="tag" title="Posts tagged with nginx">nginx</a>,php,<a href="http://icodex.org/tag/apache/" class="st_tag internal_tag" rel="tag" title="Posts tagged with apache">apache</a>,mysql,pureftpd均为最新稳定版.<span id="more-334"></span></p>
<p><strong>获取操作系统源更新</strong>.</p>
<blockquote><p>yum update<br />
yum -y install gcc gcc-c++ bison patch unzip mlocate flex wget automake autoconf gd cpp gettext readline-devel 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 libidn libidn-devel openldap openldap-devel openldap-clients openldap-servers nss_ldap expat-devel libtool libtool-ltdl-devel</p></blockquote>
<p><span style="color: #ff0000;">如果系统默认安装了apache,请先卸载.执行</span>:</p>
<blockquote><p>yum remove httpd</p></blockquote>
<p><strong>下载最新稳定版的程序源码包</strong>,以下都是到官方网站或sourceforge下载的源码包.</p>
<blockquote><p>cd /usr/local/src<br />
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.45.tar.gz/from/http://mysql.he.net/<br />
wget http://www.apache.org/dist/httpd/httpd-2.2.15.tar.gz<br />
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz<br />
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz<br />
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download<br />
wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download<br />
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download<br />
wget http://www.php.net/get/php-5.2.13.tar.gz/from/this/mirror<br />
wget http://www.lancs.ac.uk/~steveb/patches/php-mail-header-patch/php5-mail-header.patch<br />
wget http://pecl.php.net/get/memcache-2.2.5.tgz<br />
wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2<br />
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz<br />
wget http://pecl.php.net/get/imagick-2.3.0.tgz<br />
wget http://download.suhosin.org/suhosin-0.9.29.tgz<br />
wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz<br />
wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz<br />
wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz<br />
wget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz<br />
wget http://sourceforge.net/projects/pcre/files/pcre/8.01/pcre-8.01.tar.gz/download<br />
wget http://nginx.org/download/nginx-0.7.65.tar.gz<br />
wget http://download.pureftpd.org/pub/<a href="http://icodex.org/tag/pure-ftpd/" class="st_tag internal_tag" rel="tag" title="Posts tagged with pure-ftpd">pure-ftpd</a>/releases/<a href="http://icodex.org/tag/pure-ftpd/" class="st_tag internal_tag" rel="tag" title="Posts tagged with pure-ftpd">pure-ftpd</a>-1.0.28.tar.gz</p></blockquote>
<h3>一.安装Mysql.安装最新稳定版5.1.45版本,并没有采用最新开发版.</h3>
<blockquote><p>groupadd mysql -g 27<br />
useradd mysql -u 27 -g 27 -c "MySQL Server" -d /var/lib/mysql -m<br />
cd /usr/local/src<br />
tar -zxf mysql-5.1.45.tar.gz<br />
cd mysql-5.1.45<br />
./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-unix-socket-path=/var/lib/mysql/mysql.sock --with-mysqld-user=mysql --enable-assembler --enable-thread-safe-client --with-extra-charsets=all --with-big-tables --with-readline --with-<a href="http://icodex.org/tag/ssl/" class="st_tag internal_tag" rel="tag" title="Posts tagged with ssl">ssl</a> --with-embedded-server --enable-local-infile --with-plugins=partition,innodb_plugin,myisam,myisammrg<br />
make &amp;&amp; make install<br />
cd ../</p>
<p>cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf<br />
/usr/local/mysql/bin/mysql_install_db --user=mysql<br />
chown -R mysql.mysql /var/lib/mysql<br />
chgrp -R mysql /usr/local/mysql/.<br />
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql<br />
chmod u+x /etc/init.d/mysql<br />
chkconfig --level 345 mysql on<br />
echo "/usr/local/mysql/lib/mysql" &gt;&gt; /etc/ld.so.conf<br />
echo "/usr/local/lib" &gt;&gt;/etc/ld.so.conf<br />
ldconfig<br />
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql<br />
ln -s /usr/local/mysql/include/mysql /usr/include/mysql<br />
ln -s /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config<br />
service mysql start<br />
/usr/local/mysql/bin/mysqladmin -u root password root<br />
service mysql restart<br />
service mysql stop</p></blockquote>
<h3>二.编译安装apache(httpd).apache的执行用户为nobody.</h3>
<blockquote><p>cd /usr/local/src<br />
tar -zxf httpd-2.2.15.tar.gz<br />
cd httpd-2.2.15<br />
./configure --prefix=/usr/local/apache --enable-headers --enable-mime-magic --enable-proxy --enable-rewrite --enable-ssl --enable-suexec  --disable-userdir --with-included-apr --with-mpm=prefork --with-ssl=/usr --with-suexec-caller=nobody --with-suexec-docroot=/ --with-suexec-gidmin=100 --with-suexec-logfile=/usr/local/apache/logs/suexec_log --with-suexec-uidmin=100 --with-suexec-userdir=public_html<br />
make<br />
make install<br />
mkdir /usr/local/apache/domlogs<br />
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd</p></blockquote>
<p><strong>1.编辑/etc/init.d/httpd</strong>,在首行#!/bin/sh下添加:</p>
<blockquote><p># Startup script for the Apache Web Server<br />
#<br />
# chkconfig: - 85 15<br />
# description: Apache is a World Wide Web server.  It is used to serve \<br />
#              HTML files and CGI.<br />
# processname: httpd<br />
# pidfile: /usr/local/apache/logs/httpd.pid<br />
# config: /usr/local/apache/conf/httpd.conf</p>
<p>ulimit -n 1024<br />
ulimit -n 4096<br />
ulimit -n 8192<br />
ulimit -n 16384<br />
ulimit -n 32768</p></blockquote>
<p>保存退出.</p>
<p><strong>2.配置apache配置参数文件httpd.conf,位于/usr/local/apache/conf/目录</strong></p>
<blockquote><p>cd /usr/local/apache/conf/<br />
mv httpd.conf httpd.conf.bak<br />
mkdir vhosts<br />
vi httpd.conf</p></blockquote>
<p>输入以下内容:</p>
<pre>PidFile logs/httpd.pid
LockFile logs/accept.lock
ServerRoot "/usr/local/apache"
Listen 0.0.0.0:81
User nobody
Group nobody
ServerAdmin admin@evlit.com
ServerName host.evlit.com

Timeout 300
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 5
UseCanonicalName Off
AccessFileName .htaccess
TraceEnable Off
ServerTokens ProductOnly
FileETag None
ServerSignature Off
HostnameLookups Off

# LoadModule perl_module modules/mod_perl.so

DocumentRoot "/usr/local/apache/htdocs"
&lt;Directory "/"&gt;
 Options ExecCGI FollowSymLinks Includes IncludesNOEXEC -Indexes -MultiViews SymLinksIfOwnerMatch
 Order allow,deny
 Allow from all
 AllowOverride All
&lt;/Directory&gt;

&lt;Directory "/usr/local/apache/htdocs"&gt;
 Options Includes -Indexes FollowSymLinks
 AllowOverride None
 Order allow,deny
 Allow from all
&lt;/Directory&gt;

DefaultType text/plain
RewriteEngine on
AddType text/html .shtml
AddHandler cgi-script .cgi .pl .plx .ppl .perl
AddHandler server-parsed .shtml
&lt;IfModule mime_module&gt;
    TypesConfig conf/mime.types
    AddType application/perl .pl .plx .ppl .perl
    AddType application/x-img .img
    AddType application/x-httpd-php .php .php3 .php4 .php5 .php6
    AddType application/x-httpd-php-source .phps
    AddType application/cgi .cgi
    AddType text/x-sql .sql
    AddType text/x-log .log
    AddType text/x-config .cnf conf
    AddType text/x-registry .reg
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddType application/x-tar .tgz
    AddType application/rar .rar
    AddType application/x-compressed .rar
    AddType application/x-rar .rar
    AddType application/x-rar-compressed .rar
    AddType text/vnd.wap.wml .wml
    AddType image/vnd.wap.wbmp .wbmp
    AddType text/vnd.wap.wmlscript .wmls
    AddType application/vnd.wap.wmlc .wmlc
    AddType application/vnd.wap.wmlscriptc .wmlsc
&lt;/IfModule&gt;

&lt;IfModule dir_module&gt;
 DirectoryIndex index.html index.htm index.shtml index.php index.perl index.pl index.cgi
&lt;/IfModule&gt;

&lt;Files ~ "^error_log$"&gt;
 Order allow,deny
 Deny from all

 Satisfy All
&lt;/Files&gt;

&lt;FilesMatch "^\.ht"&gt;
 Order allow,deny
 Deny from all
 Satisfy All
&lt;/FilesMatch&gt;

ErrorLog "logs/error_log"
LogLevel warn

&lt;IfModule log_config_module&gt;
 LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
 LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common

 &lt;IfModule logio_module&gt;
 LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
 &lt;/IfModule&gt;
 CustomLog "logs/access_log" common
&lt;/IfModule&gt;

&lt;IfModule alias_module&gt;
 ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
&lt;/IfModule&gt;

&lt;Directory "/usr/local/apache/cgi-bin"&gt;
 AllowOverride None
 Options None
 Order allow,deny
 Allow from all
&lt;/Directory&gt;

&lt;IfModule mpm_prefork_module&gt;
 StartServers          3
 MinSpareServers       3
 MaxSpareServers       5
 MaxClients          150
 MaxRequestsPerChild   1024
&lt;/IfModule&gt;

&lt;IfModule mod_headers.c&gt;
&lt;FilesMatch "\.(html|htm|shtml)$"&gt;
Header set Cache-Control "max-age=3600, must-revalidate"
&lt;/FilesMatch&gt;
&lt;/IfModule&gt;

ReadmeName README.html
HeaderName HEADER.html

IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

Include conf/extra/httpd-languages.conf

&lt;Location /server-status&gt;
 SetHandler server-status
 Order deny,allow
 Deny from all
 Allow from 127.0.0.1
&lt;/Location&gt;
ExtendedStatus On

&lt;Location /server-info&gt;
 SetHandler server-info
 Order deny,allow
 Deny from all
 Allow from 127.0.0.1
&lt;/Location&gt;

&lt;IfModule ssl_module&gt;
Listen 0.0.0.0:443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLCipherSuite ALL:!ADH:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP
SSLPassPhraseDialog  builtin
SSLSessionCache         dbm:/usr/local/apache/logs/ssl_scache
SSLSessionCacheTimeout  300
SSLMutex  file:/usr/local/apache/logs/ssl_mutex
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
&lt;/IfModule&gt;

#Vhosts
NameVirtualHost 127.0.0.1:81
NameVirtualHost *

&lt;VirtualHost 127.0.0.1:81 *&gt;
 ServerName host.evlit.com
 DocumentRoot /var/www/html
 ServerAdmin admin@evlit.com
&lt;/VirtualHost&gt;

Include conf/vhosts/*</pre>
<p>上述虚拟主机配置中出现的127.0.0.1请改为你本机公网IP.</p>
<h3>三.编译安装php(mod_php)</h3>
<p><strong>1.编译安装相关支持库</strong></p>
<blockquote><p>cd /usr/local/src<br />
tar -zxf libiconv-1.13.1.tar.gz<br />
cd libiconv-1.13.1/<br />
./configure<br />
make<br />
make install</p>
<p>cd /usr/local/src<br />
tar -jxf libmcrypt-2.5.8.tar.bz2<br />
cd libmcrypt-2.5.8/<br />
./configure<br />
make<br />
make install<br />
/sbin/ldconfig<br />
cd libltdl/<br />
./configure --enable-ltdl-install<br />
make<br />
make install</p>
<p>cd /usr/local/src<br />
tar -jxf mhash-0.9.9.9.tar.bz2<br />
cd mhash-0.9.9.9/<br />
./configure<br />
make<br />
make install</p>
<p>ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la<br />
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so<br />
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4<br />
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8<br />
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a<br />
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la<br />
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so<br />
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2<br />
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1</p>
<p>cd /usr/local/src<br />
tar -zxf mcrypt-2.6.8.tar.gz<br />
cd mcrypt-2.6.8/<br />
/sbin/ldconfig<br />
./configure<br />
make<br />
make install</p></blockquote>
<p><strong>2.编译php</strong>,这里为php打入补丁.有助于防止邮件发送被滥用(多用户)以及在邮件中提供有价值的信息.补丁介绍信息请访问:http://www.lancs.ac.uk/~steveb/patches/php-mail-header-patch/</p>
<blockquote><p>cd /usr/local/src<br />
tar -zxf php-5.2.13.tar.gz<br />
patch -d php-5.2.13 -p1 &lt; php5-mail-header.patch<br />
cd php-5.2.13<br />
./configure --prefix=/usr/local --with-config-file-path=/etc --with-apxs2=/usr/local/apache/bin/apxs --enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-magic-quotes --enable-mbstring --enable-pdo=shared --enable-soap --enable-sockets --enable-zip --with-bz2 --with-curl --with-curlwrappers --with-freetype-dir --with-gd --with-gettext --with-jpeg-dir --with-kerberos --with-libexpat-dir=/usr --with-libxml-dir=/usr --with-mcrypt=/usr --with-mhash=/usr --with-mysql=/usr --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=/usr/bin/mysql_config --with-openssl=/usr --with-openssl-dir=/usr --with-pdo-mysql=shared --with-pdo-sqlite=shared --with-png-dir=/usr --with-sqlite=shared --with-ttf --with-xmlrpc --with-zlib -with-zlib-dir=/usr<br />
make ZEND_EXTRA_LIBS='-liconv'<br />
make install<br />
cp php.ini-dist /etc/php.ini</p></blockquote>
<p><strong>3.安装php扩展模块</strong></p>
<blockquote><p>cd /usr/local/src<br />
tar -zxf memcache-2.2.5.tgz<br />
cd memcache-2.2.5/<br />
phpize<br />
./configure --with-php-config=/usr/local/bin/php-config --with-zlib-dir --enable-memcache<br />
make<br />
make install</p>
<p>cd /usr/local/src<br />
tar -jxf eaccelerator-0.9.6.tar.bz2<br />
cd eaccelerator-0.9.6/<br />
phpize<br />
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/bin/php-config<br />
make<br />
make install<br />
mkdir -p /tmp/eaccelerator<br />
chmod 777 /tmp/eaccelerator<br />
echo "mkdir -p /tmp/eaccelerator" &gt;&gt; /etc/rc.local<br />
echo "chmod 777 /tmp/eaccelerator" &gt;&gt; /etc/rc.local</p>
<p>cd /usr/local/src<br />
tar -zxf ImageMagick.tar.gz<br />
cd ImageMagick-*<br />
./configure<br />
make<br />
make install</p>
<p>cd /usr/local/src<br />
tar -zxf imagick-2.3.0.tgz<br />
cd imagick-2.3.0/<br />
phpize<br />
./configure --with-php-config=/usr/local/bin/php-config<br />
make<br />
make install</p>
<p>cd /usr/local/src<br />
tar -zxf suhosin-0.9.29.tgz<br />
cd suhosin-0.9.29<br />
phpize<br />
./configure<br />
make<br />
make install</p>
<p>cd /usr/local/src<br />
tar -zxf ioncube_loaders_lin_x86.tar.gz<br />
cd ioncube<br />
mkdir /usr/local/ioncube<br />
mv ioncube_loader_lin_5.2.so /usr/local/ioncube/</p>
<p>cd /usr/local/src<br />
tar -zxf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz<br />
mkdir -p /usr/local/Zend/lib/Optimizer-3.3.9/php-5.2.x<br />
cp ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/Zend/lib/Optimizer-3.3.9/php-5.2.x/ZendOptimizer.so</p></blockquote>
<p><strong>3.1.修改php.ini</strong>.</p>
<p>查找/etc/php.ini中的extension_dir = "./".将其修改为extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613/"<br />
查找;include_path = ".:/php/includes",删除前面的分号,并修改为include_path = ".:/usr/lib/php:/usr/local/lib/php"<br />
跳到最后一行,然后添加以下内容:</p>
<blockquote><p>extension = "memcache.so"<br />
extension = "pdo.so"<br />
extension = "pdo_mysql.so"<br />
extension = "pdo_sqlite.so"<br />
extension = "sqlite.so"<br />
extension = "eaccelerator.so"<br />
eaccelerator.shm_size = 32<br />
eaccelerator.cache_dir = "/tmp/eaccelerator"<br />
eaccelerator.enable = 1<br />
eaccelerator.optimizer = 0<br />
eaccelerator.debug = 0<br />
eaccelerator.name_space = ""<br />
eaccelerator.check_mtime = 1<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 = 0<br />
eaccelerator.compress_level = 9<br />
eaccelerator.keys = shm<br />
eaccelerator.sessions = shm<br />
eaccelerator.content = shm</p>
<p>zend_extension = "/usr/local/ioncube/ioncube_loader_lin_5.2.so"<br />
zend_extension = "/usr/local/Zend/lib/Optimizer-3.3.9/php-5.2.x/ZendOptimizer.so"</p></blockquote>
<p><strong>4,安装Memcached</strong>(<span style="color: #ff0000;">可选</span>)</p>
<blockquote><p>cd /usr/local/src<br />
tar -xzf libevent-1.4.13-stable.tar.gz<br />
cd libevent-1.4.13-stable<br />
./configure<br />
make<br />
make install<br />
echo "/usr/local/lib/" &gt; /etc/ld.so.conf.d/libevent.conf<br />
ldconfig -v</p>
<p>cd /usr/local/src<br />
tar -xzf memcached-1.4.4.tar.gz<br />
cd memcached-1.4.4<br />
./configure<br />
make<br />
make install</p></blockquote>
<p>基本使用方法:</p>
<p>启动:/usr/local/bin/memcached -d -m 64 -p 11211 -u nobody -l localhost<br />
关闭:killall -9 memcached</p>
<h3>四.安装nginx</h3>
<p><strong>1.安装pcre库</strong></p>
<blockquote><p>cd /usr/local/src<br />
tar -zxf pcre-8.01.tar.gz<br />
cd pcre-8.01<br />
./configure<br />
make<br />
make install</p></blockquote>
<p><strong>2.安装nginx</strong></p>
<blockquote><p>cd /usr/local/src<br />
tar -zxf nginx-0.7.65.tar.gz<br />
cd nginx-0.7.65<br />
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --pid-path=/usr/local/nginx/logs/nginx.pid --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --http-client-body-temp-path=/tmp/nginx_client --http-proxy-temp-path=/tmp/nginx_proxy --http-fastcgi-temp-path=/tmp/nginx_fastcgi --with-http_stub_status_module<br />
make<br />
make install</p></blockquote>
<p><strong>2.1.添加init控制脚本</strong></p>
<pre>#! /bin/sh
ulimit -n 65535
# Description: Startup script for nginx
# chkconfig: 2345 55 25

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

set -e
[ -x "$DAEMON" ] || exit 0

do_start() {
 $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}

do_stop() {
 kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}

waitforexit() {
 count=${2:-30}
 while [ 0$count -gt 0 ]
 do
   PIDS=`ps -C$NAME --no-heading e | grep $DAEMON` || break
   PIDS=`echo "$PIDS" | awk '{print $1}' | tr '\n' ' '`
   echo Remaining processes: $PIDS
   do_stop
   sleep 2
   count=`expr $count - 1`
 done
 if [ 0$count -eq 0 ];
 then
   echo Remaining processes: $PIDS
   return 1
 fi
 return 0
}

do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}

case "$1" in
 start)
 echo -n "Starting $DESC: $NAME"
 do_start
 echo "."
 /etc/init.d/httpd start
 ;;
 stop)
 echo -n "Stopping $DESC: $NAME"
 do_stop
 echo "."
 /etc/init.d/httpd stop
 ;;
 reload)
 echo -n "Reloading $DESC configuration..."
 do_reload
 echo "."
 /etc/init.d/httpd restart
 ;;
 restart)
 echo -n "Restarting $DESC: $NAME"
 waitforexit "nginx" 20
 do_start
 echo "."
 /etc/init.d/httpd restart
 ;;
 *)
 echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" &gt;&amp;2
 exit 3
 ;;
esac

exit 0</pre>
<p>保存退出,给该文件赋予执行权限并设置开机启动</p>
<blockquote><p>chmod 755 /etc/init.d/nginx<br />
chkconfig --level 345 nginx on</p></blockquote>
<p><strong>2.2.修改nginx配置文件</strong>,位于:/usr/local/nginx/conf/目录</p>
<blockquote><p>mkdir -p /var/cache/nginx/cached<br />
chmod 600 /var/cache/nginx/cached<br />
cd /usr/local/nginx/conf/<br />
mv nginx.conf nginx.conf.bak<br />
mkdir vhosts<br />
vi nginx.conf</p></blockquote>
<p>输入以下内容:</p>
<pre>worker_processes  2;
worker_rlimit_nofile  20480;
events {
worker_connections  20480;
use epoll;
}
error_log  /usr/local/nginx/logs/error.log info;
http {
server_name_in_redirect off;
server_names_hash_max_size 2048;
server_names_hash_bucket_size 256;
include    mime.types;
default_type  application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout  60;
gzip on;
gzip_http_version 1.0;
gzip_min_length  1100;
gzip_comp_level  3;
gzip_buffers  4 32k;
# gzip_types    text/plain application/x-javascript text/xml text/css;
gzip_types    text/plain text/xml text/css application/x-javascript application/xml application/xml+rss text/javascript application/atom+xml;
ignore_invalid_headers on;
client_header_timeout  300;
client_body_timeout 300;
send_timeout     30;
reset_timedout_connection on;
connection_pool_size  256;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
request_pool_size  32k;
output_buffers   4 32k;
postpone_output  1460;
proxy_cache_path  /var/cache/nginx/cached levels=2:2 keys_zone=global:100m inactive=60m max_size=500m;
proxy_temp_path  /tmp/nginx_proxy;
include "/usr/local/nginx/conf/vhosts/*.conf";
}</pre>
<p>保存退出.</p>
<h3>五.为apache安装rpaf模块,该模块用于apache做后端时获取访客真实的IP.</h3>
<p><strong>1.使用apxs安装模块</strong>.这里要使用此前apache编译安装后的apxs</p>
<blockquote><p>cd /usr/local/src/<br />
tar -zxf mod_rpaf-0.6.tar.gz<br />
cd mod_rpaf-0.6<br />
/usr/local/apache/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c</p></blockquote>
<p><strong>2.编辑/usr/local/apache/conf/httpd.conf</strong>,添加模块参数,查找LoadModule php5_module modules/libphp5.so,在下方添加:</p>
<blockquote><p>LoadModule rpaf_module modules/mod_rpaf-2.0.so<br />
#Mod_rpaf settings<br />
RPAFenable On<br />
RPAFproxy_ips 127.0.0.1 [your_ips]<br />
RPAFsethostname On<br />
RPAFheader X-Forwarded-For</p></blockquote>
<p>上面出现的[your_ips]请修改为你本机所监听web服务的ip.多个IP用空格空开.</p>
<h3>六.安装ftp服务器:pure-ftpd</h3>
<p><strong>1.编译安装</strong></p>
<blockquote><p>cd /usr/local/src/<br />
tar -zxf pure-ftpd-1.0.28.tar.gz<br />
cd pure-ftpd-1.0.28<br />
./configure --prefix=/usr/local/pureftpd --with-language=simplified-chinese --with-everything<br />
make<br />
make install<br />
chmod 755 configuration-file/pure-config.pl<br />
cp configuration-file/pure-config.pl /usr/local/pureftpd/sbin/<br />
mkdir /usr/local/pureftpd/etc/<br />
cp configuration-file/pure-ftpd.conf /usr/local/pureftpd/etc/<br />
ln -s /usr/local/pureftpd/bin/pure-pw /usr/local/bin/</p></blockquote>
<p><strong>2.配置pure-ftpd</strong>,这里采用PureDB的验证方式.</p>
<blockquote><p>vi /usr/local/pureftpd/etc/pure-ftpd.conf</p></blockquote>
<p>查找 PureDB /etc/pureftpd.pdb 取消前面的#号并设置成PureDB/usr/local/pureftpd/etc/pureftpd.pdb<br />
查找 PassivePortRange 取消前面的#号<br />
其他参数根据需要进行修改</p>
<p><strong>3.添加自启动</strong>.这里不创建init脚本.直接放在/etc/rc.local启动即可</p>
<blockquote><p>echo "/usr/local/pureftpd/sbin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf --daemonize" &gt;&gt; /etc/rc.local</p></blockquote>
<p><strong><span style="color: #ff0000;">至此.所有安装工作结束</span></strong>.</p>
<h2>如何使用这套系统</h2>
<h3>一,做好必要的安全工作</h3>
<p>设置用户家目录/home/user,相关配置参数文件,以及访问日志等目录的权限.</p>
<blockquote><p>chmod 711 /home<br />
chmod 711 /usr/local/pureftpd/etc<br />
chmod 711 /usr/local/apache/conf/vhosts<br />
chmod 711 /usr/local/nginx/conf/vhosts<br />
chmod 711 /usr/local/apache/domlogs<br />
chmod 711 /usr/local/apache/logs<br />
chmod 600 /var/cache/nginx/cached</p></blockquote>
<h3>二,如何创建用户</h3>
<p>创建用户分两个步骤.第一步创建系统用户.该命令直接创建用户家目录.第二步创建ftp用户.创建该用户依赖系统用户的创建.步骤如下(以创建用户名为admin为例):</p>
<blockquote><p>useradd admin -m -s /sbin/nologin<br />
pure-pw useradd admin -u admin -g admin -d /home/admin -m[<span style="color: #ff0000;">第一次执行不可用</span>]<br />
pure-pw mkdb[<span style="color: #ff0000;">仅限第一次执行</span>]</p></blockquote>
<p>注意.通过上述方法安装的ftp服务器在第一次创建用户的时候不可以在pure-pw useradd ...后直接添加参数-m更新ftp用户数据库.需要分两步执行.以后可以直接在创建用户时在后面添加参数-m,执行之后会提示让你输入密码.需要重复输入两次.</p>
<h3>三.如何绑定域名</h3>
<p>由于采用前后端操作.因此需要修改两个服务器软件的虚拟主机参数.实例如下(以admin.com为例,用户目录承接上文的/home/admin):</p>
<p><strong>1.创建nginx虚拟主机参数</strong></p>
<p>首先先把公共cache参数和proxy参数写进文件中</p>
<blockquote><p>cd /usr/local/nginx/conf<br />
touch cache.inc proxy.inc</p></blockquote>
<p>然后分别编辑者两个文件。</p>
<p>vi cache.inc</p>
<blockquote><p>proxy_cache       global;<br />
proxy_cache_key   $host$uri$is_args$args;<br />
#proxy_cache_valid 200 302 10m;<br />
#proxy_cache_valid 301 1h;<br />
#proxy_cache_valid any 1m;<br />
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;<br />
proxy_temp_file_write_size 64k;<br />
proxy_max_temp_file_size   56m;</p></blockquote>
<p>vi proxy.inc</p>
<blockquote><p>proxy_connect_timeout 30s;<br />
proxy_send_timeout   300;<br />
proxy_read_timeout   300;<br />
proxy_buffer_size    64k;<br />
proxy_buffers     16 32k;<br />
proxy_busy_buffers_size 64k;<br />
#proxy_pass http://127.0.0.1:81;<br />
proxy_redirect  off;<br />
proxy_hide_header  Vary;<br />
proxy_set_header   Host   $host;<br />
proxy_set_header   X-Real-IP  $remote_addr;<br />
proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;</p></blockquote>
<p>然后再编辑虚拟主机文件就会很清晰了</p>
<blockquote><p>cd /usr/local/nginx/conf/vhosts<br />
touch admin.com.conf<br />
vi admin.com.conf<br />
输入以下内容:</p></blockquote>
<pre>server {
error_log /var/log/nginx/vhost-error_log warn;
listen 127.0.0.1:80;
server_name admin.com www.admin.com;
access_log /usr/local/apache/domlogs/admin.com combined;
location / {
root /home/admin/public_html;
proxy_cache_valid 200 301 302 10m;
proxy_cache_valid any 1m;
expires 1d;
proxy_pass http://127.0.0.1:81;
include proxy.inc;
include cache.inc;
}
location ~ .*\.(jpg|jpeg|png|gif|bmp|ico|js|css|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$ {
proxy_cache_valid  200 10s;
expires 7d;
proxy_pass http://127.0.0.1:81;
include proxy.inc;
include cache.inc;
}
location ~ .*\.(php|jsp|cgi)?$ {
proxy_pass http://127.0.0.1:81;
include proxy.inc;
}
location ~ /\.ht {
deny all;
}
}</pre>
<p>保存退出,注意将上述出现的127.0.0.1替换本机监听web服务的IP</p>
<p><strong>2.创建apache虚拟主机配置文件</strong></p>
<blockquote><p>cd /usr/local/apache/conf/vhosts<br />
touch admin.com.conf<br />
vi admin.com.conf<br />
输入以下内容:</p></blockquote>
<pre>&lt;VirtualHost 127.0.0.1:81&gt;
 ServerName admin.com
 ServerAlias www.admin.com
 DocumentRoot /home/admin/public_html
 ServerAdmin admin@evlit.com
 UseCanonicalName Off
 php_admin_value open_basedir "/home/admin:/usr/lib/php:/usr/local/lib/php:/tmp"
 &lt;IfModule !mod_disable_suexec.c&gt;
 SuexecUserGroup admin admin
 &lt;/IfModule&gt;
 ScriptAlias /cgi-bin/ /home/admin/public_html/cgi-bin/
&lt;/VirtualHost&gt;</pre>
<p>保存退出,注意将上述出现的127.0.0.1替换本机监听web服务的IP,用户名admin改为虚拟主机用户的名称.</p>
<h3>四.如何管理MySQL数据库</h3>
<p><strong>1.下载最新版PhpMyAdmin源码包</strong></p>
<blockquote><p>mkdir -p /var/www/html<br />
chmod -R 711 /var/www<br />
cd /var/www/html<br />
wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/3.3.3/phpMyAdmin-3.3.3-all-languages.zip/download<br />
unzip phpMyAdmin-3.3.3-all-languages.zip<br />
mv phpMyAdmin-3.3.3-all-languages phpmyadmin</p></blockquote>
<p><strong>2.增加apache配置</strong>,编辑httpd.conf,转到最后一行</p>
<blockquote><p>cd /usr/local/apache/conf<br />
vi httpd.conf /* shift+g转到最后一行 */<br />
#Managed Tools<br />
&lt;VirtualHost 127.0.0.1:81 *&gt;<br />
ServerName localhost<br />
ServerAlias pma.*<br />
DocumentRoot /var/www/html/phpmyadmin<br />
ServerAdmin admin@localhost<br />
UseCanonicalName Off<br />
&lt;/VirtualHost&gt;</p></blockquote>
<p>同样,修改上述出现的127.0.0.1为你提供web服务的IP.重启apache后.我们打开绑定到服务器IP的pma.yourdomain.com即可访问到phpmyadmin.第一次使用.需要进行配置.具体配置请善用Google.</p>
<p>其他没有照顾到的地方自行添加即可.如perl,sendmail等.</p>
<p><span style="color: #ff0000;"><strong>为方便管理员添加用户及绑定域名.我编写了一个脚本.</strong></span></p>
<blockquote><p>wget http://icodex.org/vhosts<br />
chmod 755 vhosts<br />
./vhosts</p></blockquote>
<p>本文地址为:<a href="http://icodex.org/2010/03/nginx-apache-guide/">http://icodex.org/2010/03/nginx-apache-guide/</a></p>
<p>--------------------------------- END ---------------------------------</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://icodex.org/2010/05/directadmin-nginx-automated-installer/" title="[更新]适用于Directadmin面板的Nginx自动安装脚本">[更新]适用于Directadmin面板的Nginx自动安装脚本</a> (55)</li><li><a href="http://icodex.org/2010/05/%e7%bb%99directadmin%e9%9d%a2%e6%9d%bf%e5%a2%9e%e5%8a%a0nginx%e5%89%8d%e7%ab%af/" title="给DirectAdmin面板增加nginx前端">给DirectAdmin面板增加nginx前端</a> (3)</li><li><a href="http://icodex.org/2010/02/nginx%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac-for-cpanel/" title="[更新]nginx 自动安装脚本 For cPanel">[更新]nginx 自动安装脚本 For cPanel</a> (62)</li><li><a href="http://icodex.org/2010/11/google%e6%8e%a8%e5%87%baapache%e5%8a%a0%e9%80%9f%e6%a8%a1%e5%9d%97mod_pagespeed/" title="Google推出apache加速模块mod_pagespeed">Google推出apache加速模块mod_pagespeed</a> (1)</li><li><a href="http://icodex.org/2010/05/nginx-0day-by-80sec/" title="nginx文件类型错误解析漏洞">nginx文件类型错误解析漏洞</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://icodex.org/2010/03/nginx-apache-guide/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>[更新]nginx 自动安装脚本 For cPanel</title>
		<link>http://icodex.org/2010/02/nginx%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac-for-cpanel/</link>
		<comments>http://icodex.org/2010/02/nginx%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac-for-cpanel/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 19:54:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[codex]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cPanel]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://icodex.org/?p=76</guid>
		<description><![CDATA[版本更新啦！现在安装包支持proxy_cache模块，支持密码保护目录、自定义错误页面等。并且支持wildcard泛域名解析！如果需要更新新版本的nginx前端。先卸载旧版本，再安装新版本。如果你有任何意见或建议，请与我联系。 2010-11-08 updated 此版本暂不支持cpanel 11.26以上的版本. 为cPanel主机添加nginx服务器软件,这样可以让nginx跑在前端处理静态文件,并且加装nginx后的资源消耗比单纯跑apache少很多.在找cPanel hack的资料的时候,刚好看到cPanel官方论坛上的一个牛人写的一个安装脚本,仔细拜读了一遍代码之后,决定在自己的cPanel服务器上安装.在使用过程中也渐渐发现了一些可以优化.可以增加的特性,主要是nginx上的一些新特性,籍由这些特性,完成了平时似乎不能完成的功能,例如在高并发的机器上实现的服务器端的缓存功能,以及nginx作为前端的时候使用.htaccess进行目录保护.这些特性都大大方便了我们的使用. 这里引用cPanel Forums上的帖子.作者blargman写了一个专门为cPanel打造的nginx自动安装脚本. Evidently I don't know hot to post in the right forum. This is an automated nginx installer for cpanel. Integrates so that domain adding/removal is all done automatically. Some people had asked for cpanel support. In lieu of that, this does pretty much everything I can [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">版本更新啦！现在安装包支持proxy_cache模块，支持密码保护目录、自定义错误页面等。并且支持wildcard泛域名解析！如果需要更新新版本的nginx前端。先卸载旧版本，再安装新版本。如果你有任何意见或建议，请与我联系。</span></p>
<p><span style="color: #ff0000;">2010-11-08 updated 此版本暂不支持cpanel 11.26以上的版本.</span></p>
<p>为cPanel主机添加nginx服务器软件,这样可以让nginx跑在前端处理静态文件,并且加装nginx后的资源消耗比单纯跑apache少很多.在找cPanel hack的资料的时候,刚好看到cPanel官方论坛上的一个牛人写的一个安装脚本,仔细拜读了一遍代码之后,决定在自己的cPanel服务器上安装.在使用过程中也渐渐发现了一些可以优化.可以增加的特性,主要是nginx上的一些新特性,籍由这些特性,完成了平时似乎不能完成的功能,例如在高并发的机器上实现的服务器端的缓存功能,以及nginx作为前端的时候使用.htaccess进行目录保护.这些特性都大大方便了我们的使用.</p>
<p>这里引用cPanel Forums上的帖子.作者<a rel="nofollow" href="http://forums.cpanel.net/members/blargman/">blargman</a>写了一个专门为cPanel打造的nginx自动安装脚本.</p>
<blockquote><p>Evidently I don't know hot to post in the right forum.</p>
<p>This is an automated <a href="http://icodex.org/tag/nginx/" class="st_tag internal_tag" rel="tag" title="Posts tagged with nginx">nginx</a> installer for <a href="http://icodex.org/tag/cpanel/" class="st_tag internal_tag" rel="tag" title="Posts tagged with cPanel">cpanel</a>. Integrates so that  domain adding/removal is all done automatically.<br />
Some people had asked for cpanel support. In lieu of that, this does  pretty much everything I can think of that they would do. It creates a  vhost for each domain/addon/subdomain and serves up static content.</p>
<p>Let me know if you have any thoughts/questions or better yet  suggestions.<br />
<a onclick="pageTracker._trackPageview  ('/out/http_blargman_com_public_tar');" rel="nofollow" href="http://blargman.com/public.tar" target="_blank">http://blargman.com/public.tar</a></p></blockquote>
<p>以上是作者原文,原文地址:<a href="http://forums.cpanel.net/f5/nginx-automated-installer-148109.html">点击这里</a>.</p>
<p><span id="more-76"></span>安装方法很简单(建议做好备份),如下:</p>
<blockquote><p><code>cd /usr/local/src<br />
wget http://blargman.com/public.tar<br />
tar xf public.tar<br />
cd publicnginx<br />
./nginxinstaller install</code></p></blockquote>
<p>安装好之后,重启nginx,执行命令:<strong>/etc/init.d/nginx restart</strong>.Nginx的配置文件均在<strong>/etc/nginx</strong>当中,各用户绑定的域名(附加域,子域等)均在<strong>/etc/nginx/vhosts</strong></p>
<p>卸载:</p>
<p><code>进入publicnginx目录后执行</code><code>./nginxinstaller uninstall.</code></p>
<p>-------------------------------------------------------------------------------------------------------------------------------------</p>
<p>我在作者编写代码的基础上增加了缓存功能,以及更多功能上的支持,例如防盗链,自定义错误页面等.为方便大家使用.做出的修改我已经打包成修改版的安装包.</p>
<p>有朋友问到我的版本和论坛里原版本的差别是在哪.我的版本解决了哪些问题.这是大部分用户的问题,这里集中进行回答.</p>
<p>1.完善的目录密码保护功能 -- 这个在原作者的安装包里面,并不能做到,原因在于没有对401状态码进行判断.<br />
2.伪静态功能的实现 -- 不管你的是以html结尾的还是以"/" 结尾的URL地址,nginx会提前判断文件系统中是否存在该文件/目录,如果不存在,那么就会匹配到后端的apache.后端的apache根据.htaccess文件的设置,进行页面的展示,前端nginx获取到内容后便进行压缩,然后传递给访客浏览器中.<br />
3.访问日志准确记录 -- 原作者的安装包中,是nginx与apache共用同个日志文件进行记录.nginx记录静态页面的访问信息,apache记录动态页面访问信息,理论上可行.但在实际使用中,我发现了这个问题.这个问题一个突破口在于对后缀.html匹配的时候,同时查询了前端nginx及后端的apache.这样就造成了日志的重复.另外一个是一些没有匹配到的后缀,前端不仅处理了访客的请求并进行记录,还会向后端发起请求查询.但由于大文件不会很快就传输完毕,因此即便设置了keepalive也无济于事.在我的安装包中,我将后端的用户配置中非加密端口的日志功能取消了,完全由前端的nginx进行记录.<br />
4.日志切割问题 -- 这个问题来自前面说的第3点修改,如果只是修改了第3点而没有进行这一步,那么就会碰到一个问题:当执行用户访问日志切割并转为统计页面展示给用户看,系统会自动将用户的日志删除,导致这之后的日志访问信息丢失直至下次nginx重启.在对cpanel日志统计进程的跟踪后,找出/usr/local/cpanel/bin/safeapacherestart这行.这行的作用是让日志切割后的apache可以安全的重新启动.解决办法就是一改作者重启nginx的方式,我将重启nginx的信息加入apache的重启命令中,以后只需要对apache进行命令操作就可以了.<br />
5.泛域名解析 -- cpanel支持泛域名解析,而且在作为主机商而言,泛域名也是一个特色,需要用起来.但是作者的版本以及我之前修改的版本中,并没有对这块进行支持,一旦客户绑定了泛域名,就会使nginx无法启动,全部用户的网站受影响.那么这次的更新就包含了这个功能.<br />
6.基于proxy_cache的缓存系统 -- 这个是我添加的,为可选功能.</p>
<p>另外需要注意的,网友们提到的一个是重启nginx后的那一串提示.这个警告信息是提示你主机名存在错误,不影响使用.</p>
<p>安装方法与作者原版一样.请执行如下安装!</p>
<p><code>cd /usr/local/src<br />
wget http://icodex.org/public.tar<br />
tar xf public.tar<br />
cd publicnginx<br />
./nginxinstaller install</code></p>
<p><span style="color: #ff0000;">注意:如果之前安装了作者原版本的nginx,请先卸载后再执行安装.</span></p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://icodex.org/2010/05/directadmin-nginx-automated-installer/" title="[更新]适用于Directadmin面板的Nginx自动安装脚本">[更新]适用于Directadmin面板的Nginx自动安装脚本</a> (55)</li><li><a href="http://icodex.org/2010/05/%e7%bb%99directadmin%e9%9d%a2%e6%9d%bf%e5%a2%9e%e5%8a%a0nginx%e5%89%8d%e7%ab%af/" title="给DirectAdmin面板增加nginx前端">给DirectAdmin面板增加nginx前端</a> (3)</li><li><a href="http://icodex.org/2010/03/nginx-apache-guide/" title="[更新]搭建前后端web生产环境">[更新]搭建前后端web生产环境</a> (21)</li><li><a href="http://icodex.org/2010/11/google%e6%8e%a8%e5%87%baapache%e5%8a%a0%e9%80%9f%e6%a8%a1%e5%9d%97mod_pagespeed/" title="Google推出apache加速模块mod_pagespeed">Google推出apache加速模块mod_pagespeed</a> (1)</li><li><a href="http://icodex.org/2010/05/nginx-0day-by-80sec/" title="nginx文件类型错误解析漏洞">nginx文件类型错误解析漏洞</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://icodex.org/2010/02/nginx%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac-for-cpanel/feed/</wfw:commentRss>
		<slash:comments>62</slash:comments>
		</item>
		<item>
		<title>为nginx虚拟主机配置startssl免费https证书</title>
		<link>http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/</link>
		<comments>http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 05:12:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[codex]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://icodex.org/?p=14</guid>
		<description><![CDATA[StartSSL是一个免费颁发SSL证书的机构,被多数有 Linux 背景的软件支持(以Mozilla的Firefox和Thunderbird为首).以前IE是没有StartSSL的根证书的,以至于一段时间IE都会将使用StartSSL证书的网站列为不受信任的网站. 但是现在情况有所改观了,今年9月份,StartCom公司出现在Windows根证书认证程序厂商更新当中,因此StartSSL证书在IE平台上已经可以正常使用的.另外Chrome,苹果Safari浏览器都可以正常识别StartSSL颁发的证书.但是Opera浏览器仍然不能支持. 为 nginx虚拟主机配置startssl证书 前提条件:独立IP.一台Linux机器.Startssl账户申请这里就不说明了.申请很简单,验证域名所有权也很简单.这里就做证书的配置. 我们先为域名生成证书请求文件和密钥.需要生成2048位加密的证书请求.以icodex.org为例,执行命令: openssl req -new -newkey rsa:2048 -nodes -out icodex.csr -keyout icodex.key 执行之后在/etc/nginx/certs目录中就有icodex.csr. 执行cat icodex.csr查看里面的内容并复制: 然后将复制的粘贴到startssl后 台,这里每一步都进行截图: 第一步: 第二步: 第三步: 第四步: 第五步: 第六步: 第七步: 第八步: 最后一步注意要先将这段代码保存为icodex.crt 放在与icodex.csr icodex.key同个目录. 然后配置nginx,直接丢配置上来. server { listen       443; listen       80; server_name  os.icodex.org; root   /home/icodex/os/public_html; index index.html index.htm index.php; access_log  /var/log/nginx/os.icodex.org-access.log  access; ssl    on; ssl_certificate    [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.startssl.com/">StartSSL</a>是一个免费颁发SSL证书的机构,被多数有 Linux 背景的软件支持(以Mozilla的Firefox和Thunderbird为首).以前IE是没有StartSSL的根证书的,以至于一段时间IE都会将使用StartSSL证书的网站列为不受信任的网站.</p>
<p>但是现在情况有所改观了,今年9月份,StartCom公司出现在Windows根证书认证程序厂商更新当中,因此StartSSL证书在IE平台上已经可以正常使用的.另外Chrome,苹果Safari浏览器都可以正常识别StartSSL颁发的证书.但是Opera浏览器仍然不能支持.<span id="more-14"></span></p>
<h2>为 nginx虚拟主机配置startssl证书</h2>
<p>前提条件:独立IP.一台Linux机器.Startssl账户申请这里就不说明了.申请很简单,验证域名所有权也很简单.这里就做证书的配置.</p>
<p>我们先为域名生成证书请求文件和密钥.需要生成2048位加密的证书请求.以icodex.org为例,执行命令:</p>
<blockquote><p>openssl req -new -newkey rsa:2048 -nodes -out icodex.csr -keyout  icodex.key</p></blockquote>
<p><a rel="attachment wp-att-15" href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/attachment/1/"><img class="alignnone size-medium wp-image-15" title="1" src="http://www.icodex.org/wp-content/uploads/2010/02/1-400x283.jpg?e97550" alt="" width="400" height="283" /></a></p>
<p>执行之后在/etc/<a href="http://icodex.org/tag/nginx/" class="st_tag internal_tag" rel="tag" title="Posts tagged with nginx">nginx</a>/certs目录中就有icodex.csr. 执行cat icodex.csr查看里面的内容并复制:</p>
<p><a rel="attachment wp-att-16" href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/attachment/2/"><img class="alignnone size-medium wp-image-16" title="2" src="http://www.icodex.org/wp-content/uploads/2010/02/2-400x245.jpg?e97550" alt="" width="400" height="245" /></a></p>
<p>然后将复制的粘贴到startssl后 台,这里每一步都进行截图:</p>
<p>第一步:<br />
<a rel="attachment wp-att-17" href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/attachment/3/"><img class="alignnone size-medium wp-image-17" title="3" src="http://www.icodex.org/wp-content/uploads/2010/02/3-400x172.jpg?e97550" alt="" width="400" height="172" /></a></p>
<p>第二步:<br />
<a rel="attachment wp-att-18" href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/attachment/4/"><img class="alignnone size-medium wp-image-18" title="4" src="http://www.icodex.org/wp-content/uploads/2010/02/4-400x195.jpg?e97550" alt="" width="400" height="195" /></a></p>
<p>第三步:<br />
<a rel="attachment wp-att-19" href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/attachment/5/"><img class="alignnone size-medium wp-image-19" title="5" src="http://www.icodex.org/wp-content/uploads/2010/02/5-400x240.jpg?e97550" alt="" width="400" height="240" /></a></p>
<p>第四步:<br />
<a rel="attachment wp-att-20" href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/attachment/6/"><img class="alignnone size-medium wp-image-20" title="6" src="http://www.icodex.org/wp-content/uploads/2010/02/6-400x171.jpg?e97550" alt="" width="400" height="171" /></a></p>
<p>第五步:<br />
<a rel="attachment wp-att-21" href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/attachment/7/"><img class="alignnone size-medium wp-image-21" title="7" src="http://www.icodex.org/wp-content/uploads/2010/02/7-400x156.jpg?e97550" alt="" width="400" height="156" /></a></p>
<p>第六步:<br />
<a rel="attachment wp-att-22" href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/attachment/8/"><img class="alignnone size-medium wp-image-22" title="8" src="http://www.icodex.org/wp-content/uploads/2010/02/8-399x195.jpg?e97550" alt="" width="399" height="195" /></a></p>
<p>第七步:<br />
<a rel="attachment wp-att-23" href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/attachment/9/"><img class="alignnone size-medium wp-image-23" title="9" src="http://www.icodex.org/wp-content/uploads/2010/02/9-399x158.jpg?e97550" alt="" width="399" height="158" /></a></p>
<p>第八步:<br />
<a rel="attachment wp-att-24" href="http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/attachment/10/"><img class="alignnone size-medium wp-image-24" title="10" src="http://www.icodex.org/wp-content/uploads/2010/02/10-400x219.jpg?e97550" alt="" width="400" height="219" /></a></p>
<p>最后一步注意要先将这段代码保存为icodex.crt 放在与icodex.csr icodex.key同个目录.</p>
<p>然后配置nginx,直接丢配置上来.</p>
<blockquote><p>server {<br />
listen       443;<br />
listen       80;<br />
server_name  os.icodex.org;<br />
root   /home/icodex/os/public_html;<br />
index index.html index.htm index.php;<br />
access_log  /var/log/nginx/os.icodex.org-access.log   access;</p>
<p><a href="http://icodex.org/tag/ssl/" class="st_tag internal_tag" rel="tag" title="Posts tagged with ssl">ssl</a>    on;<br />
ssl_certificate    /etc/nginx/certs/icodex.crt;<br />
ssl_certificate_key     /etc/nginx/certs/icodex.key;<br />
ssl_session_timeout 5m;</p>
<p>ssl_protocols SSLv2 SSLv3 TLSv1;<br />
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;<br />
ssl_prefer_server_ciphers   on;</p>
<p>location ~* ^.+\.(js|css|jpg|jpeg|gif|png|ico|bmp|swf)$ {<br />
expires      7d;<br />
}</p>
<p># pass the PHP scripts to FastCGI server<br />
#<br />
location ~ .*\.php$ {<br />
fastcgi_index  index.php;<br />
fastcgi_pass    127.0.0.1:9000;<br />
include        fastcgi_params;<br />
<strong>fastcgi_param   <a href="http://icodex.org/tag/https/" class="st_tag internal_tag" rel="tag" title="Posts tagged with https">HTTPS</a> on;</strong><br />
}<br />
}</p></blockquote>
<p>最后重启nginx.完毕...</p>
<p>另外,昨日与Showfom(此君 域名我妒忌)聊天的时候谈到火狐中文版验证ssl时提示ssl不受信任的问题,这应该是根证书的问题,后来测试,果然解决了.我们知道在apache有  SSLCertificateChainFile用来指定CA根证书位置,虽然nginx没有这个字段来指定,但是在nginx和lighttpd中是可  以将CA根证书与我们自己的证书合并使用的(声明来源:Sudone).步骤如下:</p>
<p>我们先到startssl下载 CA根证书,地址:http://cert.startssl.com/certs /,然后进入我们的证书保存位置,注意,操作前记得备份原证书文件.</p>
<blockquote><p>cd /etc/nginx/certs/<br />
cp  icodex.crt  icodex.crt.bak<br />
wget http://www.startssl.com/certs/ca.pem<br />
cat ca.pem &gt;&gt; icodex.crt</p></blockquote>
<p>最后重启nginx即可.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://icodex.org/2010/05/directadmin-nginx-automated-installer/" title="[更新]适用于Directadmin面板的Nginx自动安装脚本">[更新]适用于Directadmin面板的Nginx自动安装脚本</a> (55)</li><li><a href="http://icodex.org/2010/05/nginx-0day-by-80sec/" title="nginx文件类型错误解析漏洞">nginx文件类型错误解析漏洞</a> (0)</li><li><a href="http://icodex.org/2010/05/%e7%bb%99directadmin%e9%9d%a2%e6%9d%bf%e5%a2%9e%e5%8a%a0nginx%e5%89%8d%e7%ab%af/" title="给DirectAdmin面板增加nginx前端">给DirectAdmin面板增加nginx前端</a> (3)</li><li><a href="http://icodex.org/2010/03/nginx-apache-guide/" title="[更新]搭建前后端web生产环境">[更新]搭建前后端web生产环境</a> (21)</li><li><a href="http://icodex.org/2010/02/nginx%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac-for-cpanel/" title="[更新]nginx 自动安装脚本 For cPanel">[更新]nginx 自动安装脚本 For cPanel</a> (62)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://icodex.org/2010/02/%e4%b8%banginx%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aestartssl%e5%85%8d%e8%b4%b9https%e8%af%81%e4%b9%a6/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using disk: enhanced
Database Caching 25/60 queries in 1.348 seconds using disk: basic
Object Caching 1835/1886 objects using disk: basic
Content Delivery Network via www.icodex.org

Served from: icodex.org @ 2012-02-06 11:48:11 -->
