Nginx and Daemontools – nginx can’t bind – (98: Address already in use.)

A common question or issue that I’ve noted when helping customers when using nginx with daemontools is a flood of messages to the error log relating to a failure to bind on port 80 (or whichever port is configured) like the following:

==> logs/error.log <==
2012/09/24 17:41:48 [emerg] 27628#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2012/09/24 17:41:49 [emerg] 27637#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2012/09/24 17:41:50 [emerg] 27646#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2012/09/24 17:41:51 [emerg] 27657#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2012/09/24 17:41:52 [emerg] 27671#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2012/09/24 17:41:53 [emerg] 27680#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2012/09/24 17:41:54 [emerg] 27689#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2012/09/24 17:41:55 [emerg] 27699#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2012/09/24 17:41:56 [emerg] 27708#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2012/09/24 17:41:57 [emerg] 27725#0: bind() to 0.0.0.0:80 failed (98: Address already in use)

This is caused by daemontools starting nginx successfully, and then nginx daemonizes, and then daemontools tries to start nginx again, unsuccessfully, logging an error to the log.

The solution to this problem is to disable daemon mode in the main section of the nginx.conf:

daemon off;

Once this addition to the configuration file is made, kill all nginx processes and allow daemontools to restart. The error should no longer be logged.

(Assuming nginx version 1.2.3 for this option.)

Leave a Reply