当前位置:Gxlcms > PHP教程 > 将nginx做成服务并开机启动centos开机启动ubuntu开机启动设置nginx开机启

将nginx做成服务并开机启动centos开机启动ubuntu开机启动设置nginx开机启

时间:2021-07-01 10:21:17 帮助过:38人阅读

  1. [root@localhost ~]#vi /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. #nginx程序路径
  11. nginxd=/usr/sbin/nginx
  12. #nginx配置文件路径
  13. nginx_c/nginx/nginx.conf
  14. #nginx pid文件的路径,可以在nginx的配置文件中找到
  15. nginx_pid=/var/run/nginx/nginx.pid
  16. RETVAL=0
  17. prog="nginx"
  18. # Source function library.
  19. . /etc/rc.d/init.d/functions
  20. # Source networking configuration.
  21. . /etc/sysconfig/network
  22. # Check that networking is up.
  23. [ ${NETWORKING} = "no" ] && exit 0
  24. [ -x $nginxd ] || exit 0
  25. # Start nginx daemons functions.
  26. start() {
  27. if [ -e $nginx_pid ];then
  28. echo "nginx already running...."
  29. exit 1
  30. fi
  31. echo -n $"Starting $prog: "
  32. daemon $nginxd -c ${nginx_config}
  33. RETVAL=$?
  34. echo
  35. [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
  36. return $RETVAL
  37. }
  38. # Stop nginx daemons functions.
  39. stop() {
  40. echo -n $"Stopping $prog: "
  41. killproc $nginxd
  42. RETVAL=$?
  43. echo
  44. [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
  45. }
  46. # reload nginx service functions.
  47. reload() {
  48. echo -n $"Reloading $prog: "
  49. #kill -HUP `cat ${nginx_pid}`
  50. killproc $nginxd -HUP
  51. RETVAL=$?
  52. echo
  53. }
  54. # See how we were called.
  55. case "$1" in
  56. start)
  57. start
  58. ;;
  59. stop)
  60. stop
  61. ;;
  62. reload)
  63. reload
  64. ;;
  65. restart)
  66. stop
  67. start
  68. ;;
  69. status)
  70. status $prog
  71. RETVAL=$?
  72. ;;
  73. *)
  74. echo $"Usage: $prog {start|stop|restart|reload|status|help}"
  75. exit 1
  76. esac
  77. exit $RETVAL

  1. [root@localhost ~]#chmod +x /etc/init.d/nginx #加执行权限
  2. [root@localhost ~]#chkconfig --add nginx #将nginx做成服务
  3. [root@localhost ~]# chkconfig --list |grep nginx
  4. nginx 0:off 1:off 2:off 3:off 4:off 5:off 6:off
  5. [root@localhost ~]# chkconfig nginx on #将nginx做成开机启动
  6. [root@localhost ~]# chkconfig --list |grep nginx
  7. nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off

以上就介绍了将nginx做成服务并开机启动,包括了nginx,开机启动方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行