Bobcares

How we fixed “Nginx: [emerg] bind() to failed (98: Address already in use)” in a DigitalOcean Droplet

by | Dec 14, 2018

Nginx is one of the popular web servers used in DigitalOcean Droplets.

Unfortunately, server owners often see Nginx errors when it cannot bind to the correct port of the server.

One such error is “Nginx: [emerg] bind() to failed (98: Address already in use).”

At Bobcares, we help server owners to fix these Nginx errors as part of our Dedicated Support Services.

Today, we’ll see the steps involved in fixing the “Nginx: bind() failed: Address already in use” error.

 

What causes the error “Nginx: [emerg] bind() to failed (98: Address already in use)”?

First of all, we’ll see the exact cause for the “Nginx:[emerg] bind() to failed (98: Address already in use)” error.

It’s a matter of fact that all services on the server need a unique port to run. Thus, mail service runs on port 25, web service on port 80, secure web traffic on port 443 and so on.

Additionally, this means that two services can never run on the same port.

Therefore, this error simply means that some other service is already running on the port.

For instance, customer’s Droplet showed the following Nginx errors in the log file /var/log/nginx/error.log

2018/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)

And because of the error, web server was not listening on port 80 or 443.

 

How to fix “Nginx: [emerg] bind() to failed (98: Address already in use)” in a DigitalOcean Droplet

Now, we know that the error happens as another service is running on Nginx port. So to fix, we need to stop the current process and make Nginx listen on the port.

Let’s see the exact steps that our Expert Engineers do on the Droplet to fix the error.

 

1. Identify the service on port

First and foremost, we need to find out the process that is already running on port 80. For this, we use the command netstat. Using server root login, the exact command would be:

netstat -tulpn | grep --color :80

And, it shows the service that is already listening on port 80 of the server.

tcp6 0 0 :::80 :::* LISTEN 2078/apache2

Here, the server had both Apache and Nginx installed. And, the server owner had already started Apache and it was listening on port 80 of the Droplet. That’s why, Nginx restart showed errors.

 

2. Stop the alternate service

As the second step, we need to stop the alternate service running. To kill the process listening on port 80, we run the following command as root user.

fuser -k 80/tcp

Similarly, to kill process listening on 443, we can use the command as

fuser -k 443/tcp

After killing the process, our Support Engineers additionally verify that no service is running on port 80 of the Droplet.

 

3. Start Nginx

Now, we can start Nginx again. Prior to the restart, it is worth to check for any configuration errors in Nginx. Therefore, the exact sequence of commands that we do include:

nginx -t

Followed by a restart with the command,

service nginx start

That fixes the Nginx error in the Droplet.

[Having trouble with the web server? We can fix the Nginx errors for you.]

Conclusion

“Nginx:[emerg] bind() to failed (98: Address already in use)” is a common error that happens in DigitalOcean Droplets when more than one service tries to listen on a port. Today, we’ve seen how our Dedicated Support Engineers diagnose and fix this error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

5 Comments

  1. Diego Turcios

    Wow, thank you very much this website helped me solve the problem I was with struggling to fix. ?

    Reply
    • Hiba Razak

      Thanks for the feedback Diego.
      We are glad to know that it worked for you ? .

      Reply
  2. Greg Spivey

    still fighting with nginx for rtmp only on 1935,,, netstat returns nothing on 1935. but it stills fails,,, any idea??

    pi@raspberrypi:~ $ sudo netstat -p -a | grep 1935
    pi@raspberrypi:~ $ 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: e
    Active: failed (Result: exit-code) since Wed 2023-02-01 07:23:50 EST; 6min a
    Docs: man:nginx(8)
    Process: 21702 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_proces
    Process: 21703 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (co

    Feb 01 07:23:48 raspberrypi systemd[1]: Starting A high performance web server
    Feb 01 07:23:48 raspberrypi nginx[21703]: nginx: [emerg] bind() to 0.0.0.0:1935
    Feb 01 07:23:48 raspberrypi nginx[21703]: nginx: [emerg] bind() to 0.0.0.0:1935
    Feb 01 07:23:49 raspberrypi nginx[21703]: nginx: [emerg] bind() to 0.0.0.0:1935
    Feb 01 07:23:49 raspberrypi nginx[21703]: nginx: [emerg] bind() to 0.0.0.0:1935
    Feb 01 07:23:50 raspberrypi nginx[21703]: nginx: [emerg] bind() to 0.0.0.0:1935
    Feb 01 07:23:50 raspberrypi nginx[21703]: nginx: [emerg] still could not bind()
    Feb 01 07:23:50 raspberrypi systemd[1]: nginx.service: Control process exited,
    Feb 01 07:23:50 raspberrypi systemd[1]: nginx.service: Failed with result ‘exit
    Feb 01 07:23:50 raspberrypi systemd[1]: Failed to start A high performance web

    pi@raspberrypi:~ $

    Reply
    • Hiba Razak

      Hi Greg,
      Please contact our support through live chat(click on the icon at right-bottom).

      Reply

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF