手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

CentOS 6.2 安装Nginx 并设置为开机服务

[日期:2012-06-23] 来源:Linux社区  作者:programming [字体:大 中 小]

最后安装
make && make install 

启动nginx
进入安装目录sbin下:

./nginx 

查看nginx进程:

ps –ef | grep nginx 

设置成系统开机服务:
在 /etc/init.d/  目录下创建 nginx 文件 内容如下:

  1. #!/bin/bash   
  2. # nginx Startup script for the Nginx HTTP Server   
  3. # this script create it by gcec at 2009.10.22.   
  4. # it is v.0.0.1 version.   
  5. # if you find any errors on this scripts,please contact gcec cyz.   
  6. # and send mail to support at gcec dot cc.   
  7. #   
  8. # chkconfig: - 85 15  
  9. # description: Nginx is a high-performance web and proxy server.   
  10. #              It has a lot of features, but it's not for everyone.   
  11. # processname: nginx   
  12. # pidfile: /var/run/nginx.pid   
  13. # config: /usr/local/nginx/conf/nginx.conf   
  14.   
  15. nginxd=/app/nginx/sbin/nginx   
  16. nginx_config=/app/nginx/conf/nginx.conf   
  17. nginx_pid=/var/run/nginx.pid   
  18.   
  19. RETVAL=0  
  20. prog="nginx"  
  21.   
  22. # Source function library.   
  23. . /etc/rc.d/init.d/functions   
  24.   
  25. # Source networking configuration.   
  26. . /etc/sysconfig/network   
  27.   
  28. # Check that networking is up.   
  29. [ ${NETWORKING} = "no" ] && exit 0  
  30.   
  31. [ -x $nginxd ] || exit 0  
  32.   
  33.   
  34. # Start nginx daemons functions.   
  35. start() {   
  36.   
  37. if [ -e $nginx_pid ];then   
  38.    echo "nginx already running...."  
  39.    exit 1  
  40. fi   
  41.   
  42.    echo -n $"Starting $prog: "  
  43.    daemon $nginxd -c ${nginx_config}   
  44.    RETVAL=$?   
  45.    echo   
  46.    [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx   
  47.    return $RETVAL   
  48.   
  49. }   
  50.   
  51.   
  52. # Stop nginx daemons functions.   
  53. stop() {   
  54.         echo -n $"Stopping $prog: "  
  55.         killproc $nginxd   
  56.         RETVAL=$?   
  57.         echo   
  58.         [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid   
  59. }   
  60.   
  61.   
  62. # reload nginx service functions.   
  63. reload() {   
  64.   
  65.     echo -n $"Reloading $prog: "  
  66.     #kill -HUP `cat ${nginx_pid}`   
  67.     killproc $nginxd -HUP   
  68.     RETVAL=$?   
  69.     echo   
  70.   
  71. }   
  72.   
  73. # See how we were called.   
  74. case "$1" in   
  75. start)   
  76.         start   
  77.         ;;   
  78.   
  79. stop)   
  80.         stop   
  81.         ;;   
  82.   
  83. reload)   
  84.         reload   
  85.         ;;   
  86.   
  87. restart)   
  88.         stop   
  89.         start   
  90.         ;;   
  91.   
  92. status)   
  93.         status $prog   
  94.         RETVAL=$?   
  95.         ;;   
  96. *)   
  97.         echo $"Usage: $prog {start|stop|restart|reload|status|help}"  
  98.         exit 1  
  99. esac   
  100.   
  101. exit $RETVAL  

chkconfig --add nginx

chkconfig --level 345 nginx on

chkconfig --list nginx

启动

service nginx start

停止

service nginx stop

linux
相关资讯       Nginx安装 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款