sesc360
sesc360

Reputation: 3255

Restarting NGINX fails

I installed NGINX on Ubuntu 16.04 and edited my config. When I want to restart with sudo service nginx restart I get the error:

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

The content of nginx.service status is:

nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-01-02 16:07:54 UTC; 15s ago
  Process: 26515 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 26510 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 3464 (code=exited, status=0/SUCCESS)

Jan 02 16:07:53 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 02 16:07:53 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 
Jan 02 16:07:53 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 02 16:07:54 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 16:07:54 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 02 16:07:54 IF-STG-001 nginx[26515]: nginx: [emerg] still could not bind()
Jan 02 16:07:54 IF-STG-001 systemd[1]: nginx.service: Control process exited, code=exited status=1
Jan 02 16:07:54 IF-STG-001 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Jan 02 16:07:54 IF-STG-001 systemd[1]: nginx.service: Unit entered failed state.
Jan 02 16:07:54 IF-STG-001 systemd[1]: nginx.service: Failed with result 'exit-code'.

Why can't I restart my nginx instance? I don't see why it is blocking the restart

Upvotes: 1

Views: 1927

Answers (2)

dushyant
dushyant

Reputation: 369

This issue generally arises when you are running apache server on the same machine as apache and nginx need the same port to run i.e. 80. tried to change the nginx port to 8080 or something else. i.e. {listen 8080 default_server;listen [::]:8080 default_server;} and restart the nginx

Upvotes: 0

Holger Just
Holger Just

Reputation: 55908

The important part of the error message is

bind() to 0.0.0.0:80 failed (98: Address already in use)

Thus, when starting up, nginx could not bind to the port 80 since some other program is already bound to this port. You will only be able to start nginx when this other program exits or unbinds from this socket.

To find which program currently bind this port, you can run this command as root (e.g. with sudo):

ss -ntlp "sport = :80"

Upvotes: 2

Related Questions