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

配置nginx服务器全局命令的更多相关文章

  1. ubuntu14.04安装与配置nginx服务器

    去年曾经配置过nginx服务器,可惜的是,几个月前因故障磁盘被格式化.今天又要用到nginx服务,所以从新配置了一番,但这次就不是那么顺利了.在此,愿与大家分享一下经验.只是简单的局域网应用,并未复杂 ...

  2. Windows 配置nginx服务器 运行php项目

    1下载 http://nginx.org/en/download.html 选择稳定版下载. 2 解压后 直接双击nginx.exe 双击后一个黑色的弹窗一闪而过 3 修改配置文件nginx.conf ...

  3. Linux服务器安装配置Nginx服务器

      Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务 ...

  4. Linux安装配置Nginx服务器

    如有需要可以加我Q群[308742428]大家一起讨论技术,有偿服务. 后面会不定时为大家更新文章,敬请期待. 喜欢的朋友可以关注下. 前言 今天搭建nginx服务器,来访问静态资源文件. Nginx ...

  5. 配置nginx的systemctl命令

    启动nginx的命令为     /usr/local/nginx/sbin/nginx  停止nginx的命令为    /usr/local/nginx/sbin/nginx -s stop 重启ng ...

  6. centos6.4下配置nginx服务器更改根目录

    安装完nginx服务器后发现nginx的根目录在/usr/share/nginx/html/下,但是对于部署文件来说,在该目录下是不太习惯的,我就尝试着更改nginx访问的根目录 #  vi /etc ...

  7. nginx 服务器重启命令,关闭

    nginx -s reload  :修改配置后重新加载生效 nginx -s reopen  :重新打开日志文件nginx -t -c /path/to/nginx.conf 测试nginx配置文件是 ...

  8. nginx 服务器重启命令,关闭 (转)

    nginx -s reload  :修改配置后重新加载生效nginx -s reopen  :重新打开日志文件nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否 ...

  9. 配置nginx服务器 —— Nginx添加多个二级子域名

    1.安装nginx centos/linux下的安装Nginx 2.安装好后进入Nginx目录中 在conf目录下建立一个vhost(ps:名字自己设定)文件夹 其中的$NGINXHOME为你的ngi ...

随机推荐

  1. [LeetCode 题解]: ZigZag Conversion

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 The string ...

  2. Sublime Text 3 Settings

    Preferences - Setting User - > : { "font_size": 14, "word_wrap": true, " ...

  3. [HTTP]Nonocast.http post方法

    Nonocast.Http is a free, open source developer focused web service via http for small and medium sof ...

  4. hdu Surround the Trees

    题目链接:戳我 凸包模板 #include<iostream> #include<cstdio> #include<cstring> #include<alg ...

  5. 24. 两两交换链表中的节点 leetcode

    题目: 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表. 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换. 示例: 给定 1->2->3->4, 你应该返回 ...

  6. logstash--使用ngxlog收集windows日志

    收集流程 1nxlog => 2logstash => 3elasticsearch 1. nxlog 使用模块 im_file 收集日志文件,开启位置记录功能 2. nxlog 使用模块 ...

  7. Tomcat安装与使用

    主要讲解Tomcat的 安装与使用,讲解ubuntu版本和windows. 下载与安装: 1)到apache官网.www.apache.org http://jakarta.apache.org(产品 ...

  8. [原创] Shell 参数传递 与 默认值

    目录 简介 基本传参 $* 与 $@ 区别 默认参数(变量默认值) if 繁琐方式 - 变量为null = 变量为null时, 同时改变变量值 :- 变量为null 或 空字符串 := 变量为null ...

  9. try语句块和异常处理

    在C++中,异常处理包括: · throw表达式(throw expression) 异常检测部分使用throw表达式来表示它遇到了无法处理的问题.throw表达式抛出一个异常并把控制权转移到能处理该 ...

  10. 2019年华南理工大学程序设计竞赛(春季赛) B 修仙时在做什么?有没有空?可以来炼丹吗?(思维建图搜索)

    https://ac.nowcoder.com/acm/contest/625/B 分析: 全部的状态只有1<<18 个 , 所以我们可以预处理 f[u][j] , 然后建立出全部的u可以 ...