nginx.service not found after installation – what tools/commands should I use to determine root of issue?

stackedAndOverflowed asked:

Hosting: new droplet on Digital Ocean

Operating system: fresh install of CentOS 7.6.1810

Background: testing Nginx on Centos in 100 different ways before it is used in production.

Question: My installation of Nginx from source appears to work but the service isn’t found by the OS. Where should I start testing to find the root of the problem? I can get around Linux fine but I’m far from an expert.

Backstory: Installing Nginx with the package manager works fine. The install goes smooth and the service starts perfectly.

sudo yum install -y nginx

sudo systemctl start nginx

However when I build from source Nginx doesn’t want to start.

The install appears to go fine without problems.

curl > nginx-1.16.0.tar.gz

tar -zxvf nginx-1.16.0.tar.gz

cd nginx-1.16.0

sudo ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/ --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-file-aio --with-threads --with-http_ssl_module --with-http_v2_module

sudo make

sudo make install

However when I try to start nginx I get an error.

sudo systemctl start nginx

Failed to start nginx.service: Unit not found.

I checked /etc/nginx and nginx.conf was created properly. It’s almost as if nginx installed but somehow it didn’t check in with the OS. I’m not an expert on Centos or Linux and I’m not sure what things I should check off to determine the root of the problem.

My answer:

The nginx source tarball doesn’t include a systemd unit. If you insist on running a copy built by yourself from source then you will need to provide the systemd unit file yourself. You can find one in the RPM package.

BTW your explanation of why you aren’t doing this doesn’t make much sense; almost everyone actually needs most of the modules you have stripped out, so it is usually a waste of time to even make the attempt. Many of the truly optional modules are already loadable modules which you can simply change nginx’s configuration to not load.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.