Failed to start nginx.service: Unit not found

sir-haver picture sir-haver · Jun 10, 2019 · Viewed 20.2k times · Source

I installed the latest version of nginx and configured some directories:

./configure --sbin-path=/usr/bin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-pcre --pid-path=/var/run/nginx.pid --with-http_ssl_module

It all works completely fine. After that I created a custom file:

nano /lib/systemd/system/nginx.service

The content of the file:

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/bin/nginx -t
ExecStart=/usr/bin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

But then when running "systemctl start nginx" I get the error "unit not found":

enter image description here

I can't understnad why or what's the problem. Running "nginx -V" shows the directories are set.

Does anyone have a clue? Thanks in advance

Answer

anabeto93 picture anabeto93 · Oct 10, 2019

Try the following and let's see what happens.

 sudo yum install epel-release
 sudo yum install nginx
 sudo systemctl -l enable nginx
 sudo systemctl -l start nginx

It did not work for me initially because epel-release was not installed. But this is assuming you're using Fedora/ CentOs