I removed the default Nginx package from my server, and compiled it from source here. There is a script on the server that checks Nginx, and reports any problem:
if ($result->num_rows > 0) {
exec('sudo service nginx configtest 2>&1', $output, $returnCode);
if ($returnCode === 0) {
passthru('sudo service nginx restart');
} else {
$subject = 'Nginx config test failed on ' .gethostname();
$message = implode('<br>', $output);
Mail::sendEmail('it_staff@mydomain.com', $subject, $message);
}
}
When running service nginx configtest I get:
nginx: unrecognized service
However, running nginx -t returns:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Am I missing a configuration somewhere that I'm unaware of? Nginx is working, but it's saying it's an unrecognized service.
I created a systemd unit file with the following:
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
I also enabled and started Nginx:
sudo systemctl enable nginx.service
sudo systemctl start nginx.service
Nginx is running, and I can hit web sites using this server. What could I be missing? Thanks.