Emmanuel BRUNET
Emmanuel BRUNET

Reputation: 1406

DEBIAN 8.4 - NGINX start fails

I have 4 units running Nginx in different OS versions either on debian 8.0, 8.4 or Ubuntu 14.04. Since yesterday NGINX startup fails on my dev station (it did run nice 2 days ago).. Strange !

$ sudo service nginx start

$ Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.

so looking for the logs :

$ sudo systemctl -l status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
   Active: failed (Result: exit-code) since Thu 2016-04-28 22:15:18 CEST; 6min ago
  Process: 24148 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 24145 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

Apr 28 22:15:15 mercure nginx[24148]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:15:16 mercure nginx[24148]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:15:16 mercure nginx[24148]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:15:17 mercure nginx[24148]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:15:17 mercure nginx[24148]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:15:18 mercure nginx[24148]: nginx: [emerg] still could not bind()
Apr 28 22:15:18 mercure systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 28 22:15:18 mercure systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 28 22:15:18 mercure systemd[1]: Unit nginx.service entered failed state

and second issue :

$ sudo journalctl -xn
-- Logs begin at Thu 2016-04-28 08:41:36 CEST, end at Thu 2016-04-28 22:23:08 CEST. --
Apr 28 22:22:54 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:55 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:55 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:56 mercure nginx[24290]: nginx: [emerg] still could not bind()
Apr 28 22:22:56 mercure systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 28 22:22:56 mercure systemd[1]: Failed to start A high performance web server and a reverse proxy 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.
Apr 28 22:22:56 mercure systemd[1]: Unit nginx.service entered failed state.
Apr 28 22:22:56 mercure sudo[24263]: pam_unix(sudo:session): session closed for user root
Apr 28 22:23:08 mercure sudo[24293]: jeby6372 : TTY=pts/3 ; PWD=/etc/nginx ; USER=root ; COMMAND=/bin/journalctl -xn
Apr 28 22:23:08 mercure sudo[24293]: pam_unix(sudo:session): session opened for user root by jeby6372(uid=0)

I've found a strange DHCP behaviour in /var/log/syslog , isn't it ?

Apr 28 22:22:24 mercure NetworkManager[676]: <info> (eth0): DHCPv4 state changed renew -> renew
Apr 28 22:22:24 mercure NetworkManager[676]: <info>   address 192.168.1.3
Apr 28 22:22:24 mercure NetworkManager[676]: <info>   plen 24 (255.255.255.0)
Apr 28 22:22:24 mercure NetworkManager[676]: <info>   gateway 192.168.1.254
Apr 28 22:22:24 mercure NetworkManager[676]: <info>   server identifier 192.168.1.1
Apr 28 22:22:24 mercure NetworkManager[676]: <info>   lease time 120
Apr 28 22:22:24 mercure NetworkManager[676]: <info>   nameserver '192.168.1.1'
Apr 28 22:22:24 mercure NetworkManager[676]: <info>   domain name 'hznteam.lan'
Apr 28 22:22:24 mercure NetworkManager[676]: <info>   domain search 'hznteam.lan.'
Apr 28 22:22:24 mercure dbus[722]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr 28 22:22:24 mercure dbus[722]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr 28 22:22:24 mercure nm-dispatcher: Dispatching action 'dhcp4-change' for eth0
Apr 28 22:22:24 mercure dhclient: bound to 192.168.1.3 -- renewal in 47 seconds.
Apr 28 22:22:53 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:54 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:54 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:55 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:55 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:56 mercure nginx[24290]: nginx: [emerg] still could not bind()
Apr 28 22:22:56 mercure systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 28 22:22:56 mercure systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 28 22:22:56 mercure systemd[1]: Unit nginx.service entered failed state

.

runnin Nginx as a foreground task show that 0.0.0.0:80 is already in use, but I've no apache install

jeby6372@mercure:~$ sudo nginx -g "daemon off;"
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

the nmap command result states that no program is listening on port 80

jeby6372@mercure:~$ nmap -p 80 localhost

Starting Nmap 6.47 ( http://nmap.org ) at 2016-04-29 18:57 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000054s latency).
Other addresses for localhost (not scanned): 127.0.0.1
PORT   STATE SERVICE
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds

Any idea ?

Upvotes: 0

Views: 1514

Answers (2)

Mahabub Islam Prio
Mahabub Islam Prio

Reputation: 1085

It seems , some other service is using that address or port you are trying to access with nginx . So find out any second process which is using that port . And close it and then start the nginx .

Upvotes: 1

Peter Bauer
Peter Bauer

Reputation: 156

Try to run nginx in the foreground mode to check out what is the reason why it fails:

nginx -g "daemon off;"

If you will still get the error:

bind() to 0.0.0.0:80 failed

Then maybe a service runs already on port 80. Then try to find out which service it is with the lsof command and kill it with kill -15 or kill -9. You can check if something is running on port 80 by running:

nmap -p 80 localhost

Upvotes: 2

Related Questions