7

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

sir-haver
  • 3,096
  • 7
  • 41
  • 85
  • 1
    https://unix.stackexchange.com/questions/293875/failed-to-start-service – Chetan Jun 10 '19 at 14:26
  • 1
    Thanks a lot Chetan, it seems that "systemctl daemon-reload" solves the problem. At first I thought that the other guy's question is too different. Thanks! – sir-haver Jun 10 '19 at 14:31

1 Answers1

12

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

anabeto93
  • 307
  • 3
  • 12