Nginx是目前十分流行的轻量级的web服务器的构建平台,相对于经典的apache来说,它虽然在功能上根本无法与其匹敌,但是在业务需求专一的某些领域Nginx已经取得了领先,因为在对服务质量日益关注的今天,首先要考虑的就是在原有的设备平台上做都最优化的服务提供,Nginx的发展可以说是顺应了这个潮流的发展,以其对硬件设备的低需求而脱颖而出。目前Nginx使用的是Fast-cgi技术,这样的平台和windows的IIS所使用的API一样的优秀!
实验平台 RHEL5.4(红帽) 实验前先行设置好yum源
用到的软件
nginx-1.1.4.tar.gz
php-5.2.17-fpm-0.5.14.diff.gz(连接所用软件,是一个补丁)
php-5.2.17.tar.gz
实验的过程:
一、Nginx安装配置
[root@localhost ~]# yum -y install prce*
[root@localhost ~]# tar zxvf nginx-1.1.4.tar.gz
[root@localhost nginx-1.1.4]# ./configure --prefix=/usr/local/nginx
[root@localhost nginx-1.1.4]# make && make install
[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# vi index.php
<?php
phpinfo();
?>
[root@localhost html]# cd ../conf/
[root@localhost conf]# vi nginx.conf (红色字体为本机地址和网页的路径)
location ~ \.php$ {
root html;
fastcgi_pass 192.168.1.192:9000; //
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
[root@localhost conf]# cd /etc/init.d/
[root@localhost init.d]# vi nginxd (书写启动的shell)
#!/bin/bash
#Author ethnicity(Just a check of others)
#Time 2011-9-24
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
[root@localhost init.d]# chkconfig --add nginxd
[root@localhost init.d]# chkconfig nginxd on
[root@localhost ~]# service nginxd restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]