服务器上的nginx和php都是源码编译安装的,不支持类似以前的nginx(start|restart|stop|reload)了。自己动手丰衣足食。以下脚本应该在rhel, fedora,centos下都适用。
一、nginx启动脚本/etc/init.d/nginx#!/bin/bash
#
# startup script for nginx - this script starts and stops the nginxdaemon
#
# chkconfig: - 8515
# description: nginx is an http(s) server,http(s) reverse proxy and imap/pop3 proxy server
# processname: nginx
#config: /usr/local/nginx/conf/nginx.conf
#pidfile: /usr/local/nginx/logs/nginx.pid
# source function library.
. /etc/rc.d/init.d/functions
# source networking configuration.
. /etc/sysconfig/network
# check that networking is up.
[ $networking = no ] && exit0
nginx=/usr/local/nginx/sbin/nginx
prog=$(basename $nginx)
nginx_conf_file=/usr/local/nginx/conf/nginx.conf
[ -f /etc/sysconfig/nginx ] && ./etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $nginx_conf_file ] || exit 6
echo -n $starting $prog:
daemon $nginx -c $nginx_conf_file
retval=$?
echo
[ $retval -eq 0 ] && touch$lockfile
return $retval
}
stop() {
echo -n $stopping $prog:
killproc $prog -quit
retval=$?
echo
[ $retval -eq 0 ] && rm -f$lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $reloading $prog:
killproc $nginx -hup
retval=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $nginx_conf_file
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null2>&1
}
case $1 in
start)
rh_status_q && exit 0
$1
