centos7 Failed to start nginx.service:unit not found

刺骨的言语ヽ痛彻心扉 2023-10-04 17:52 129阅读 0赞

Failed to start nginx.service:unit not found

  • 1.在/etc/init.d下新建nginx文件
  • 2.插入代码
  • 3.进入目录/etc/init.d
  • 4.添加权限
  • 5.添加config配置
  • 6.开启nginx

1.在/etc/init.d下新建nginx文件

  1. vim /etc/init.d/nginx

2.插入代码

  1. #!/bin/sh
  2. # nginx - this script starts and stops the nginx daemin
  3. #
  4. # chkconfig: - 85 15
  5. # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
  6. # proxy and IMAP/POP3 proxy server
  7. # processname: nginx
  8. # config: /usr/local/nginx/conf/nginx.conf
  9. # pidfile: /usr/local/nginx/logs/nginx.pid
  10. # Source function library.
  11. . /etc/rc.d/init.d/functions
  12. # Source networking configuration.
  13. . /etc/sysconfig/network
  14. # Check that networking is up.
  15. [ "$NETWORKING" = "no" ] && exit 0
  16. nginx="/usr/local/nginx/sbin/nginx"
  17. prog=$(basename $nginx)
  18. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
  19. lockfile=/var/lock/subsys/nginx
  20. start() {
  21. [ -x $nginx ] || exit 5
  22. [ -f $NGINX_CONF_FILE ] || exit 6
  23. echo -n $"Starting $prog: "
  24. daemon $nginx -c $NGINX_CONF_FILE
  25. retval=$?
  26. echo
  27. [ $retval -eq 0 ] && touch $lockfile
  28. return $retval
  29. }
  30. stop() {
  31. echo -n $"Stopping $prog: "
  32. killproc $prog -QUIT
  33. retval=$?
  34. echo
  35. [ $retval -eq 0 ] && rm -f $lockfile
  36. return $retval
  37. }
  38. restart() {
  39. configtest || return $?
  40. stop
  41. start
  42. }
  43. reload() {
  44. configtest || return $?
  45. echo -n $"Reloading $prog: "
  46. killproc $nginx -HUP
  47. RETVAL=$?
  48. echo
  49. }
  50. force_reload() {
  51. restart
  52. }
  53. configtest() {
  54. $nginx -t -c $NGINX_CONF_FILE
  55. }
  56. rh_status() {
  57. status $prog
  58. }
  59. rh_status_q() {
  60. rh_status >/dev/null 2>&1
  61. }
  62. case "$1" in
  63. start)
  64. rh_status_q && exit 0
  65. $1
  66. ;;
  67. stop)
  68. rh_status_q || exit 0
  69. $1
  70. ;;
  71. restart|configtest)
  72. $1
  73. ;;
  74. reload)
  75. rh_status_q || exit 7
  76. $1
  77. ;;
  78. force-reload)
  79. force_reload
  80. ;;
  81. status)
  82. rh_status
  83. ;;
  84. condrestart|try-restart)
  85. rh_status_q || exit 0
  86. ;;
  87. *)
  88. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  89. exit 2
  90. esac

3.进入目录/etc/init.d

  1. cd /etc/init.d

4.添加权限

  1. chmod 777 /etc/init.d/nginx

5.添加config配置

  1. chkconfig --add nginx

6.开启nginx

  1. service nginx start

发表评论

表情:
评论列表 (有 0 条评论,129人围观)

还没有评论,来说两句吧...

相关阅读