Nginx: Failed to start A high performance web server and a reverse proxy server

Nginx

Nginx Problem Overview


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'.

Nginx Solutions


Solution 1 - Nginx

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

So first try this:

sudo service apache2 stop

If 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

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

Solution 2 - Nginx

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

Solution 3 - Nginx

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.

Solution 4 - Nginx

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

sudo fuser -k 80/tcp

Solution 5 - Nginx

Try to stop the process which is using port 80:

sudo fuser -k 80/tcp

When you did restart using

sudo systemctl restart nginx

Solution 6 - Nginx

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

Solution 7 - Nginx

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`)

Solution 8 - Nginx

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

Solution 9 - Nginx

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

Solution 10 - Nginx

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

Solution 11 - Nginx

I had to use:

sudo killall nginx 

And could then use;

sudo systemctl start nginx

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCibeleView Question on Stackoverflow
Solution 1 - NginxMahdi YounesiView Answer on Stackoverflow
Solution 2 - NginxfrmbelzView Answer on Stackoverflow
Solution 3 - NginxValery ViktorovskyView Answer on Stackoverflow
Solution 4 - Nginxshrikant joshiView Answer on Stackoverflow
Solution 5 - NginxSudhanView Answer on Stackoverflow
Solution 6 - NginxsanzmalzView Answer on Stackoverflow
Solution 7 - NginxDarkTrickView Answer on Stackoverflow
Solution 8 - NginxABDULLAH MAKKIView Answer on Stackoverflow
Solution 9 - NginxsudaynView Answer on Stackoverflow
Solution 10 - Nginxsadra hakimView Answer on Stackoverflow
Solution 11 - Nginxmututa paulView Answer on Stackoverflow