nGinx stops & shows apache error page


In this post we will fix the nginx server issue where it stops and the frontend of website shows the error message related to apache server.

If you check the nginx error logs, you will see something like this:

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

What causes this error?

This error is caused by apache (or httpd) server using the same port as nginx, and thus making it unavailable for nginx. This can happen mostly after a system restart (scheduled, or after a crash, etc.).

How to fix this error?

You can fix this error by simply doing any one of these steps:

  • Either change the port for apache (or nginx) from 80 to something else
  • Or disable apache completely (if you’re not using it, keep reading)

How to disable apache / httpd on nginx server

These steps will help you disable apache2 or httpd server on ubuntu or other linux operating system distros.

Note: Debian/Ubuntu uses apache2, for RHEL/CentOS/Fedora, use: httpd

How to check if apache server is running

Check if apache is running:

sudo systemctl status apache2 #Debian/Ubuntu
#or
sudo systemctl status httpd #RHEL/CentOS/Fedora

How to stop apache server on linux distro

You can stop the running apache server by using command (mask will prevent other apps from launching it too):

sudo systemctl stop apache2 # or httpd
sudo systemctl mask apache2 # or httpd

How to find if apache / httpd is enabled to run at boot

Find if apache is enabled at boot time:

sudo systemctl is-enabled apache2 # or httpd

Disable apache / httpd to start at boot

If enabled at boot time, we can disable apache from running at boot time by using command:

sudo systemctl disable apache2 # or httpd

At the end, verify the status and boot loading config by using same commands again:

sudo systemctl status apache2 # or httpd
sudo systemctl is-enabled apache2 # or httpd

How to remove / delete apache server package?

You can remove the apache2 server package from ubuntu or any other distro by using command:

sudo apt remove apache2
# or
sudo yum erase httpd httpd-tools apr apr-util

Leave a Reply

Your email address will not be published.