在freebsd7.0RC1下试验,其它平台未测试
一、安装
1、php
代码:
cd /usr/ports/lang/php5
make install clean
2、nginx
代码:
cd /usr/ports/www/nginx
make install clean
3、lighttpd
代码:
cd /usr/ports/www/lighttpd
make
cd ./work/lighttpd-1.4.18/src
cp spawn-fcgi /usr/local/bin
cd ../../../
make clean
4、启动spawn-fcgi
代码:
spawn-fcgi -a 127.0.0.1 -p 8888 -C 25 -u www -f /usr/local/bin/php-cgi
或用下面的方法更简单
代码:
#-------------------start script --------------------------------------
#!/bin/sh
SPAWNPATH="/usr/local/bin/spawn-fcgi"
PHPCGIPATH="/usr/local/bin/php-cgi"
PIDPATH="/var/run/php-cgi.pid"
case $1 in
start)
"$SPAWNPATH" -f "$PHPCGIPATH" -a 127.0.0.1 -p 8888 -P "$PIDPATH" -u www -C 5
;;
stop)
kill `cat $PIDPATH`
;;
restart)
kill -HUP `cat $PIDPATH`
;;
*)
echo $"Usage: $0 start|stop|restart"
exit 1
esac
exit 0
#------------------start script end ----------------------
把上面的脚本存入文件如phpctl 设置为可执行
运行 ./phpctl start 启动php fcgi 进程
修改nginx.conf
找到去掉前面的注释
代码:
location ~ \ .php${
fastgi_pass 127.0.0.1:8888;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/nginx$fastcgi_script_name;
include fastcgi_prams;
}
5、启动nginx
代码:
nginx -c /usr/local/etc/nginx/nginx.conf
6、开机自动启动加入/etc/rc.conf
二、控制使用
1、可接受信号
Signal Action
TERM, INT Terminate the server immediately
QUIT Stop the server
HUP Configuration changes, start new workers, graceful stop of old workers
USR1 Reopen log files
USR2 Upgrade the server executable
WINCH Graceful Stop (parent process advise the children to exit)
三、日志轮询
代码:
log_dir="/var/log/nginx"
date_dir=`date +%Y/%m/%d/%H`
/bin/mkdir -p ${log_dir}/${date_dir} > /dev/null 2>&1
/bin/mv ${log_dir}/access.log ${log_dir}/${date_dir}/access.log
/bin/mv ${log_dir}/error.log ${log_dir}/${date_dir}/error.log
kill -USR1 `cat /var/run/nginx.pid`
/bin/gzip ${log_dir}/${date_dir}/access.log &
/bin/gzip ${log_dir}/${date_dir}/error.log &