把nginx加入系统服务!!
下载源码包回来
http://nginx.org/download/nginx-1.2.4.tar.gz
编译安装。编译之前查看是否安装pcre-devel,openssl,openssl-devel。
装好之后进入nginx的目录下。默认是/usr/local/nginx
编辑一个shell脚本文件。vim /etc/init.d/nginx
1 #!/bin/bash 2 # nginx Startup script for the Nginx HTTP Server 3 # it is v.0.0.2 version. 4 # chkconfig: - 85 15 5 # description: Nginx is a high-performance web and proxy server. 6 # It has a lot of features, but it's not for everyone. 7 # processname: nginx 8 # pidfile: /var/run/nginx.pid 9 # config: /usr/local/nginx/conf/nginx.conf 10 11 nginxd=/usr/local/nginx/sbin/nginx 12 nginx_config=/usr/local/nginx/conf/nginx.conf 13 nginx_pid=/var/run/nginx.pid 14 RETVAL=0 15 prog="nginx" 16 # Source function library. 17 . /etc/rc.d/init.d/functions 18 # Source networking configuration. 19 . /etc/sysconfig/network 20 # Check that networking is up. 21 [ ${NETWORKING} = "no" ] && exit 0 22 [ -x $nginxd ] || exit 0 23 # Start nginx daemons functions. 24 start() { 25 if [ -e $nginx_pid ];then 26 echo "nginx already running...." 27 exit 1 28 fi 29 echo -n $"Starting $prog: " 30 daemon $nginxd -c ${nginx_config} 31 RETVAL=$? 32 echo 33 [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx 34 return $RETVAL 35 } 36 # Stop nginx daemons functions. 37 stop() { 38 echo -n $"Stopping $prog: " 39 killproc $nginxd 40 RETVAL=$? 41 echo 42 [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid 43 } 44 # reload nginx service functions. 45 reload() { 46 echo -n $"Reloading $prog: " 47 #kill -HUP `cat ${nginx_pid}` 48 killproc $nginxd -HUP 49 RETVAL=$? 50 echo 51 } 52 # See how we were called. 53 case "$1" in 54 start) 55 start 56 ;; 57 stop) 58 stop 59 ;; 60 reload) 61 reload 62 ;; 63 restart) 64 stop 65 start 66 ;; 67 status) 68 status $prog 69 RETVAL=$? 70 ;; 71 *) 72 echo $"Usage: $prog {start|stop|restart|reload|status|help}" 73 exit 1 74 esac 75 exit $RETVAL
保存之后,给定执行权限
1 chmod a+x /etc/init.d/nginx
设置开机启动
1 chkconfig /etc/init.d/nginx on
这样通过下面的方式就可以下了。
1 /etc/init.d/nginx start/stop/restart 2 service nginx start/stop/restart
浙公网安备 33010602011771号