2

I've installed nginx using this sources.list.d entry:

deb http://nginx.org/packages/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/ubuntu/ xenial nginx

The nginx version is 1.12.2-1~xenial. The server is running Ubuntu 16.04 LTS, with kernel 4.4.0-36-generic.

My problem is that the nginx daemon fails to start:

$ sudo systemctl start nginx
Job for nginx.service failed because a timeout was exceeded. See "systemctl status nginx.service" and "journalctl -xe" for details.

Unfortunately, these logs don't provide much information:

$ sudo journalctl -xe
Feb 05 10:43:50 SERVERNAME nginx[17035]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Feb 05 10:43:50 SERVERNAME nginx[17035]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Feb 05 10:45:21 SERVERNAME systemd[1]: nginx.service: Start operation timed out. Terminating.
Feb 05 10:45:21 SERVERNAME systemd[1]: Failed to start nginx - high performance web server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
Feb 05 10:45:21 SERVERNAME systemd[1]: nginx.service: Unit entered failed state.
Feb 05 10:45:21 SERVERNAME systemd[1]: nginx.service: Failed with result 'timeout'.

From what I can tell, nginx does indeed start correctly. It's as if the parent process doesn't receive the "I am started" message from it's child process(es) correctly being the problem. When it's running (systemd waiting for it to start), I can successfully curl it like this:

$ curl http://localhost:8000
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>

I feel lost on this, apart from perhaps testing another nginx version or something. Any ideas? I could reboot the server but it feels silly on a Linux server.

Update 9:56 UTC: Tested with 1.13.8-1~xenial, same problem.

3 Answers 3

3

I eventually found the problem, this was a silly one...

I had started out my nginx configuration by copying the settings from a Docker container, which had this setting in its nginx configuration:

daemon off;

This was right in the Docker scenario (where the nginx process was running with runit, i.e. no systemd-style init was controlling it.) It had the effect that nginx would never daemonize, and return control to systemd -> it would be treated as "timed out with unknown problem", and systemd would kill it.

So, this ended up being a simple configuration error. I wanted to post it here, since it might help others who also make this clumsy mistake. :-)

Full details about this keyword: http://nginx.org/en/docs/ngx_core_module.html#daemon

0

What might also be problematic is custom setting of pid localization in nginx.conf:

pid ../logs/nginx.pid;

it must be alligned with the PIDFile setting in nginx.service file (/lib/systemd/system/nginx.service): PIDFile=/var/run/nginx.pid

Here it is not ;]

0

This can also happen when copying the nginx configuration over to openresty. I had this line in the config and openresty would not start as a service:

pid /run/nginx.pid;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.