centos上配置nginx为服务

完成nginx基本配置后,可以把它配置服务的形式,方便管理。同时可以让该服务在系统启动时自动启动。


1. 首先配置服务脚本,建立文件 /etc/rc.d/init.d/nginx , 其内容如下:

  1.  
  2. #!/bin/sh    
  3. #chkconfig: 2345 10 90    
  4. #name: nginx   
  5. #description: Nginx Service Script   
  6. #  
  7.     
  8. case $1 in    
  9.     start)   
  10.         echo  "Starting Nginx..."  
  11.         /usr/local/nginx/sbin/nginx  -c /usr/local/nginx/conf/nginx.conf   # path
  12.         ;;    
  13.     stop)   
  14.         echo  "Stopping Nginx..."  
  15.         /usr/bin/killall  -s  QUIT  nginx  
  16.         ;;    
  17.     restart)    
  18.         echo  "Reloading Nginx..."  
  19.         $0  stop    
  20.         $0  start    
  21.          ;;    
  22.     *)    
  23.         echo  "Usage: $0 {start|stop|restart}"   
  24.        
  25. esac    
  26. exit  0

其中 # path 那行,换成自己的nginx路径 及 conf路径
保存后,别忘了 chmod 777 nginx

 

2. 配置自启动


chkconfig --add nginx    //加入到自启服务中

chkconfig --level 2345 nginx off   //调节不同系统级别启动

chkconfig --level 2345 nginx on    //调节不同系统级别启动

chkconfig | grep nginx   //查看状态

posted @ 2013-12-25 10:08  GoneWithWind  阅读(195)  评论(0编辑  收藏  举报