最近在测试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)
- stop
- start
- ;;
- try-restart|condrestart)
- if [ -f $lockfile ]; then
- stop
- start
- fi
- ;;
- reload|force-reload|reread)
- echo -n $"Re-reading $prog configuration: "
- killproc $nginx -HUP
- RETVAL=$?
- 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