nginx failed to bind port 80

How to Fix NGINX Bind to 0.0.0.0:80 Failed Error

NGINX is a popular web server used by millions of websites and organizations. Sometimes when you start NGINX server you may get ‘bind to 0.0.0.0:80 failed’ error and it may not start. In this article, we will learn how to fix this problem. This is a common issue faced by many system administrators.

How to Fix NGINX Bind to 0.0.0.0:80 Failed Error

There are several reasons why this error occurs. We will look at the most common of them.

1. Check port

Generally, NGINX gives this error, if some other process is already running on the port where you want to run NGINX server. For example, port 80 is the most commonly used port by NGINX. Sometimes you may have an Apache server running on the same port. So it will not allow NGINX to start on this port. In this case, you can either stop or kill the process running on the port and then try to start NGINX. Here is an example.

$ sudo /etc/init.d/apache2 stop

Alternatively, run the netstat command to get the process running on port 80.

# netstat -tulpn | grep :80

Note the PID of the process in the result of above command. Then use the kill command to kill that process. Replace PID below with the PID of the process to be killed.

# kill -9 PID

You can also change NGINX to run on a different port. Open NGINX configuration file.

$ vi /etc/nginx/nginx.conf

Look for the listen 80 line

server {
  ...
  listen 80;
  ...
}

Replace 80 with another port number that is available.

server {
  ... 
  listen 8000;
  ...
}

Save and quit the file. Restart NGINX server to apply changes.

2. Wrong configuration

In some cases, administrators use the following configuration to run NGINX on port 80.

listen [::]:80;

Please note, this is an IPv6 configuration and not IPv4 configuration. For IPv4, you need to use the following configuration.

listen 80;

If you want to use IPv6 configuration, you need to add ipv6only directive as shown below.

listen [::]:80 ipv6only=on;

3. Problem with default configuration

Every NGINX system ships with a default configuration file at /etc/nginx/default. You can either customize it or replace it with your own configuration. If you keep it in /etc/nginx/sites-enabled or have a symlink from /etc/nginx/sites-enabled to /etc/nginx/default then you may get this error. So it is advisable to simply delete any symlinks from /etc/nginx/sites-enabled to /etc/nginx/default using the following command.

$ sudo rm /etc/nginx/sites-enabled/default

In this article, we have learnt how to fix NGINX bind 0.0.0.0:80 failed error. Basically, this happens because some other process is running on the same port, or NGINX is not properly configured to run on port 80.

Also read:

How to Fix NGINX Unable to Load SSL Certificate
How to Detect Touchscreen Device in JavaScript
How to Fix Server Quit Without Updating PID MySQL Error
How to Change Apache Config Without Restarting
How to Change NGINX Config Without Restarting

Leave a Reply

Your email address will not be published. Required fields are marked *