当前位置: 首页 > 工具软件 > Nginx Unit > 使用案例 >

在centos下systemctl start nginx启动nginx时出现Unit nginx.service could not be found.

上官波鸿
2023-12-01

编译安装nginx 后,systemctl启动nginx时会出现:

[root@localhost ~]# systemctl start nginx
Unit nginx.service could not be found.

错误的原因就是没有添加nginx服务,所以启动失败。

解决方法:

1. 在/root/etc/init.d/目录下新建文件,文件名为nginx

  或者用命令在根目录下执行: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
 类似资料: