Fix “bind() to 0.0.0.0:80 failed (98: Address already in use)” nginx error

ADVERTISEMENT

Recently, I have been buying VPSes with various companies to test setting up a light, fast and efficient Linux box to run some of my sites.

The typical install is Debian or Ubuntu, with the LNMP stack (Linux, nginx, MySQL and PHP). I chose nginx over Apache due to its much lower resource usage and the ability to handle much more parallel connections, should traffic spikes to the sites arise.

I realize that using plain old Apache with full caching (W3 Total Cache) is an option, but I prefer to let my sites run dynamically so that some specific plugins and code work properly (they won’t, if the site is cached).

With the choice of software decided, I installed the LEMP stack and tried to set up sites on the VPS box I had. One error that I came across was, “bind() to 0.0.0.0:80 failed (98: Address already in use)”, after I installed nginx, edited the necessary configuration files (nginx.conf among others) and restarted the nginx server using the /etc/init.d/nginx restart command.

ADVERTISEMENT

I tried restarting the server, and even installed the VPS from scratch, but the error did not go away. Some poking around on the server (which included examining running processes etc.) made me realize that the error was caused by Apache being bound to the 0.0.0.0:80 port. During the LEMP stack setup, I had not removed the Apache version that was bundled with the Debian/Ubuntu template installed from the VPS management page.

The solution was easy – stop or remove the Apache software. Since I did not need Apache 2, I issued apt-get remove apache2 to uninstall it on Debian or Ubuntu servers. Alternatively, you can power down Apache 2 first, by the command sudo service apache2 stop. If you uninstalled apache2, reboot the server once and nginx should be humming along nicely.