service nginx start|stop|reload 报错:Failed to reload nginx.service: Unit not found.【解决方案】

在执行service nginx start|stop|reload 的时候报错:Failed to reload nginx.service: Unit not found

是因为nginx没有有添加到系统服务,手动手动添加一个即可。

1.创建文件

vim /etc/init.d/nginx

2.把下面的代码粘贴进去(这个代码网上一大堆)

#!/bin/sh
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server # processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0
$1
;; stop) rh_status_q || exit 0
$1
;; restart|configtest)
$1
;; reload)
rh_status_q || exit 7
$1
;; force-reload)
force_reload
;;
status)
rh_status
;; condrestart|try-restart) rh_status_q || exit 0
;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2 esac

3.进入目录

cd /etc/init.d

执行

# chmod 755 /etc/init.d/nginx

# chkconfig –add nginx

4.之后就可以使用,绝对没毛病

service nginx start | stop | reload

标签:linuxnginxservice nginx startUnit not found

最新文章

  1. Sublime Text3插件管理
  2. javascript常识
  3. AppBox升级进行时 - Entity Framework的增删改查
  4. Eclipse/JavaWeb (三)三大框架之Spring框架 持续更新中...
  5. 使用Hive或Impala执行SQL语句,对存储在HBase中的数据操作
  6. Swift - UITableViewCell倒计时重用解决方案
  7. mysql-5.6.14-winx64免安装配置
  8. BZOJ-1880 Elaxia的路线 SPFA+枚举
  9. jquery------导入jquery UI要使用的文件
  10. Buy the Ticket
  11. 妙味课堂——HTML+CSS(第三课)
  12. Spring整合Ibatis
  13. mysql_config_editor
  14. PHP文章管理
  15. JAVA中this用法小结[转]
  16. C# post请求 HttpWebRequest
  17. js中静态函数与变量
  18. Pseudoforest(伪最大生成树)
  19. Tomcat+Servlet面试题都在这里
  20. Spark技术内幕:Shuffle Pluggable框架详解,你怎么开发自己的Shuffle Service?

热门文章

  1. SharpMap开发教程——图层标注
  2. 微信开发之c#下缓存jssdk的access_token
  3. Struts2学习第4天--拦截器
  4. fillna()
  5. python 小点
  6. css3滚动条
  7. Codeforces Round #549 (Div. 2)C. Queen
  8. 快速启动工具Rulers 3.6
  9. php 中将完整的年月日时分秒的时间转换成 年月日的形式
  10. [Swift]在Swift中实现自增(++)、自减(--)运算符:利用extension扩展Int类