I recently tried adding a new site configuration for NGINX and just did what we normally do &mbsp; sudo service nginx restart. The weird thing is, my site configuration is okay (run sudo nginx -t to test your config) so something else might be wrong right?

Like what any good Geekysaur would do, we won’t stop until we find the root cause! I proceeded to look at NGINX’ runtime log using sudo nginx and saw the following error messages:

What does this mean? Basically, it means that NGINX failed to bind to port 80 of your server because, well, the address/port is already in use. This usually happens when you have several web servers (Apache2, lighttpd, etc.) installed aside from NGINX or if NGINX failed to stop or restart correctly.

To solve, this, we’d have to kill whatever process is using that port. We’d be using fuser which is a very cool unix utility function used to find which process is currently using a file, directory, or socket. It also gives other bits of information such as the user owning the process and the type of access.

The code is pretty self explanatory! sudo runs the command as root, -k or --kill issues the kill command, and 80/tcp means do it for processes using the TCP port 80. Easy right?

After that, just do another sudo service nginx restart and your NGINX server should now be working like a charm!

Did you learn something new from this post? Do you know of any other ways on how we could have solved this issue? Let your fellow Geekysaurs know by hitting us up in the comments below!