当前位置:首页 > 服务器类 > Windows服务器 > > 更换apache到nginx的操作过程全记录

更换apache到nginx的操作过程全记录

点击次数:167 次 发布日期:2008-09-18 21:09:00 作者:源代码网
源代码网推荐

源代码网整理以下客户有一个跑了3年多的组装pc服务器, 1.5G内存,p4 2.8G cpu,apache2.28+mod_php+mysql。95%的页面是静态页,每天大约有各类http请求500-1000万个(包括html,js,css,jpg,gif,php等)   启用了gzip压缩,大部分时间负载在1.0以下,但是偶尔会暴涨,导致死机,严重情况一天down机N次。一直没找到原因,可能是服务器不行了。 正好想测试一下nginx + php-fastcgi 性能,也许能行。 说干就干,看了一些nginx文档,开始实施了。过程如下:

源代码网整理以下安装php最新版,直接用自带的fastcgi模式:
./configure --prefix=/usr/local/php526cgi --with-mysql=/usr/local/mysql --with-zlib=/usr/local/src/zlib --with-gd --with-freetype-dir=/usr/local/src/freetype --with-jpeg-dir=/usr/local/src/jpeg/lib --enable-gd-native-ttf --with-png-dir=/usr/local/src/libpng --enable-exif --enable-ftp --with-curl --enable-mbstring=all --enable-force-cgi-redirect --enable-zip --enable-zend-multibyte  --enable-fastcgi

源代码网整理以下make
make install

源代码网整理以下由于已经是有php环境了,zlib等组件早已安装好。我只需要--enable-fastcgi就ok了。 php搞定!

源代码网整理以下mysql不动它,继续用。

源代码网整理以下执行php-fastcgi:

源代码网整理以下我们可以利用Lighttpd的spawn-fcgi来控制cgi进程的运行。获得spawn-fcgi的方法如下:

源代码网整理以下wget http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2 #获取Lighttpd的源码包
tar -xvjf lighttpd-1.4.18.tar.bz2
cd lighttpd-1.4.18
./configure --prefix=/usr/local/lighttpd
make
cp src/spawn-fcgi /usr/local/nginx/bin/spawn-fcgi #取出spawn-fcgi的程序
下面我们就可以使用 spawn-fcgi 来控制php-cgi的FastCGI进程了

源代码网整理以下/usr/local/nginx/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 32 -u nobody -g nobody -f /usr/local/php526cgi/bin/php-cgi

源代码网整理以下好了,搞定。继续。

源代码网整理以下
安装nginx:
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module

源代码网整理以下make
make install

源代码网整理以下strip /usr/local/nginx/sbin/nginx 可以压缩执行文件,节约内存

源代码网整理以下制作nginx启动脚本:
vi /usr/local/nginx/bin/mynginx

源代码网整理以下#!/bin/bash
case $1 in
start)
        /usr/local/nginx/sbin/nginx
;;
stop)
        killall -9 nginx
;;
test)
        /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
;;
restart)
        ps auxww | grep nginx | grep master | awk "{print $2}" | xargs kill -HUP
;;
show)
        ps -aux|grep nginx
;;
esac

源代码网整理以下用法一看就知道了。

源代码网整理以下设置nginx的配置文件,这个网上一大把,不重复了。有需要的可以上 http://nginx.myhbcms.cn/ 找找

源代码网整理以下将apache的httpd.conf里面的虚拟主机配置转到nginx里去,由于有几十个虚拟主机,这个花了我好几个小时的时间。

源代码网整理以下额外插曲:由于使用了apache的mod_vhosts虚拟主机模块,nginx没找到对应的功能模块,不得以,只好继续在8081端口开着apache,用nginx的proxy来反向代理。举例:
        server {
                listen 80;
                server_name *.hbcms.com *.myhbcms.cn;

源代码网整理以下                location / {
                    proxy_pass http://127.0.0.1:8081/;  // 这是apache运行的端口
                    proxy_set_header   Host             $host;
                    proxy_set_header   X-Real-IP        $remote_addr;
                    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

源代码网整理以下                }
        }

源代码网整理以下大致过程就是这样了,希望对你有所帮助。 至于这个服务器性能会如何,运行一段时间才知道。理论上来说nginx应该会比apache资源占用上小很多。

源代码网供稿.
网友评论 (0)
会员中心
服务器类
本站推荐
服务器类之精华