63

I try to start this service but i can´t, the error below occur:

root@zabbix:/home/appliance# systemctl status nginx.service

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 Wed 2018-07-25 18:33:26 UTC; 1min 27s ago
  Process: 30040 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 30037 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

Jul 25 18:33:25 zabbix nginx[30040]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:25 zabbix nginx[30040]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:25 zabbix nginx[30040]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:26 zabbix nginx[30040]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:26 zabbix nginx[30040]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:26 zabbix nginx[30040]: nginx: [emerg] still could not bind()
Jul 25 18:33:26 zabbix systemd[1]: nginx.service: Control process exited, code=exited status=1

Jul 25 18:33:26 zabbix systemd[1]: *******Failed to start A high performance web server*** and a reverse proxy server.****

Jul 25 18:33:26 zabbix systemd[1]: nginx.service: Unit entered failed state.
Jul 25 18:33:26 zabbix systemd[1]: nginx.service: Failed with result 'exit-code'.

13 Answers 13

131

You already have a process bound to the HTTP port 80 (Specially after upgrading systems! it will start apache2 by default)

So try this first :

sudo service apache2 stop
sudo systemctl restart nginx

If the problem is not solved then run this command sudo lsof -i:80 to get a list of processes using the port and then stop or disable web server.

Try to stop the process which are using the port 80 using :

sudo fuser -k 80/tcp
sudo systemctl restart nginx

In some cases it may be some issues in the configuration file.

You can use nginx -t -c /etc/nginx/nginx.conf command to find any miss-configuration.

In some cases this error is caused by a default Nginx site already on port 80, removing default config works if you don't need a default one.

sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
5
  • 5
    Seriously? I can not believe this could be an issue. Thanks a lot for saving my day.
    – iTR
    Jun 1, 2020 at 5:04
  • 1
    Tnx much, it happend just randomly, maybe someone restarted server machine :) Oct 6, 2020 at 11:24
  • 1
    LMAO! Best Answer! Specially after upgrading systems! it will start apache2 by default. Thanks dude
    – misterzik
    Dec 26, 2020 at 23:57
  • 1
    Wonderful mate. Misleading messages are often cause of wasting time and thus less time is spent on innovations. :)
    – Jag
    Mar 15, 2021 at 0:36
  • 1
    You are great, Sir; please keep helping us. Sep 6, 2022 at 2:12
57

For me this error was caused by a default nginx site already on port 80. Removing default site worked

sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
1
  • 1
    sudo unlink /etc/nginx/sites-enabled/default
    – Dgloria
    Jan 1, 2022 at 22:44
32

You already have a process bound to the HTTP port 80. You can run command sudo lsof -i:80 to get a list of processes using the port and then stop/disable web server.

16

Try to stop the process which are using the port 80:

sudo fuser -k 80/tcp
2
  • This will solve the problem now, but at a reboot, if that process is enabled, it will occupy the network port again.
    – Alex M.M.
    Jun 20, 2020 at 0:34
  • thanks. its saves my time. Feb 8, 2022 at 12:36
14

Try to stop the process which is using port 80:

sudo fuser -k 80/tcp

When you did restart using

sudo systemctl restart nginx
13

It may be some issues in the configuration file. You can use this nginx -t -c /etc/nginx/nginx.confcommand to find any bugs in the configuration file. If you find the bugs resolve that run the sudo service nginx restart again. It will work.

Please check the reference here

4

In my experience, this error can be triggered in several different situations (which might have the same root, but are perceived as different scenarios).

Not only port 80

Depending on your nginx config, you should also try port 443:

  • sudo lsof -i:80
  • sudo lsof -i:443

You should be able to check your nginx listen ports in /etc/nginx/sites-enabled (under Debian)

Special case

In my case, there was an nginx instance running, that would block itself from restarting. It would not go down with sudo systemctl stop nginx. I had to use sudo killall nginx and could then use sudo systemctl start nginx.

Config error

I also experienced the exact same error message on a config error.

You can check your nginx config with /usr/sbin/nginx -c /etc/nginx/nginx.conf@ (this will also test all virtual host files (/etc/nginx/sites-enabled`)

4

I had to use:

sudo killall nginx 

And could then use;

sudo systemctl start nginx
0
3

i had same issue, was because i have apache and nginx on same server ! so when i typed sudo reboot it didn't work because it started apache while am using nginx so i just run this two commands

sudo systemctl stop apache2 then sudo systemctl start nginx

then sudo systemctl disable apache2 so next time i reboot not going to face same issue

help from aws services support

1
  • 2
    Thank you, so much!
    – Akif
    Mar 7, 2021 at 20:26
2

For me stopping apache service solved the problem sudo service apache2 stop

0
1

I had this problem too. I checked the /etc/nginx/site-available/default file and I have forgotten to close the bracket (syntax error).

1

Just restart the nginx server. It should resolve your problem sudo systemctl restart nginx

1

I was using gunicorn with nginx, found that service was not active.

sudo systemctl enable gunicorn.socket
sudo systemctl start gunicorn.socket
sudo systemctl restart nginx

Worked for me.

if your gunicorn is active, please make sure it's working fine.

you can also go through the logs(errors) via nginx logs from

sudo tail -f /var/log/nginx/error.log

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.