最近在測試LNMP,是以會有筆記。
在我的機子下測試是成功的。
這隻是截取了腳本的部份。
# vi /etc/init.d/nginx
#!/bin/sh
#
# nginx This shell script takes care of starting and stopping
# The Nginx HTTP Server.
#This script create it by Hunk at 2011.12.12.
#it is v1.0 version.
# chkconfig: - 85 15
# description: Nginx HTTP Server.
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile: /var/run/nginx/nginx.pid
nginx=/usr/sbin/nginx/nginx
nginx_config=/etc/nginx/nginx.conf
nginx_pid=/var/run/nginx/nginx.pid
lockfile=/var/lock/nginx
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is enabled.
[ ${NETWORKING} = "no" ] && exit 1
#Start nginx daemons functions
start(){
if [ -e $nginx_pid ];then
echo "nginx already running..."
exit 1
fi
echo -n $"Starting $prog:"
daemon $nginx -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
return $RETVAL
}
stop() {
echo -n $"Shutting down $prog: "
killproc $nginx
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
status)
status $nginx
RETVAL=$?
restart)
try-restart|condrestart)
if [ -f $lockfile ]; then
stop
start
fi
reload|force-reload|reread)
echo -n $"Re-reading $prog configuration: "
killproc $nginx -HUP
echo
*)
echo -n "Usage: $prog {start|stop|restart|try-restart|reload|status"}
exit 2
esac
exit $RETVAL
設定腳本權限:
# chmod a+x /etc/init.d/nginx
測試:
# netstat -tnlp | grep 80
打開你的浏覽器試吧。
本文轉自 ljpwinxp 51CTO部落格,原文連結:http://blog.51cto.com/191226139/738982