I know this topic exists in various different forms, but I'm having trouble solving my problem. If I run service nginx restart, nginx fails with the following log:

2015/03/14 08:36:42 [emerg] 9400#0: bind() to failed (98: Address already in use)
2015/03/14 08:36:42 [emerg] 9400#0: bind() to failed (98: Address already in use)
2015/03/14 08:36:42 [emerg] 9400#0: bind() to failed (98: Address already in use)
2015/03/14 08:36:42 [emerg] 9400#0: bind() to failed (98: Address already in use)
2015/03/14 08:36:42 [emerg] 9400#0: bind() to failed (98: Address already in use)
2015/03/14 08:36:42 [emerg] 9400#0: still could not bind()

I only have one config loading in sites-enabled. When I run:

$ grep -slir "listen 80"
$ sites-available/default

It shows that the default config has listen 80, but that shouldn't matter since it's not in sites-enabled.

$ ps ax -o pid,ppid,%cpu,vsz,wchan,command|egrep '(nginx|PID)'
 9468     1  0.0  97188 sigsus nginx: master process /usr/sbin/nginx
 9471  9468  0.0  97328 ep_pol nginx: worker process
 9472  9468  0.0  97368 ep_pol nginx: worker process
 9693  9641  0.0   9448 pipe_w egrep --color=auto (nginx|PID)

Here's a netstat showing what ports are being used:

$ netstat -tulpn

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0    *               LISTEN      1300/master
tcp        0      0   *               LISTEN      9468/nginx
tcp        0      0  *               LISTEN      5980/monit
tcp        0      0*               LISTEN      1174/mysqld
tcp        0      0*               LISTEN      1155/memcached
tcp        0      0    *               LISTEN      9468/nginx
tcp        0      0    *               LISTEN      1113/sshd
tcp6       0      0 :::25                   :::*                    LISTEN      1300/master
tcp6       0      0 :::9000                 :::*                    LISTEN      9106/hhvm
tcp6       0      0 :::22                   :::*                    LISTEN      1113/sshd
udp        0      0*                           1155/memcached

And here is my complete config in sites-enabled (the only one in there):

server {
    listen                  443 ssl default_server;

    limit_conn              gulag 15;
    server_name             www.my-website.com;

    access_log              /home/my-website/logs/access.log;
    error_log               /home/my-website/logs/error.log info;

    root                    /home/my-website/web;
    index                   index.php index.html;

    ssl_certificate /etc/nginx/ssl/my-website.com.chained.crt;
    ssl_certificate_key /etc/nginx/ssl/my-website.com.key;
    ssl_prefer_server_ciphers On;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    include                 /etc/nginx/includes/my-website_redirects_https.inc;
    include                 /etc/nginx/includes/file_cache.inc;
    include                 /etc/nginx/includes/wordpress.inc;

server {
    listen                  80;
    server_name             my-website.com www.my-website.com;
    return                  301 https://$server_name$request_uri;

server {
    listen                  443;
    server_name             my-website.com;
    return                  301 https://www.$server_name$request_uri;

server {
        some-other-website1.com         www.some-other-website1.com
        some-other-website2.com         www.some-other-website2.com
        some-other-website3.com         www.some-other-website3.com
        some-other-website4.com         www.some-other-website4.com
        some-other-website5.com         www.some-other-website5.com

    rewrite ^(.*)$ https://www.my-website.com/some/page/ permanent;

server {
        some-other-website6.com         www.some-other-website6.com
        some-other-website7.com         www.some-other-website7.com
        some-other-website8.com         www.some-other-website8.com

    rewrite ^(.*)$ https://www.my-website.com/some/other/page/ permanent;

server {
    server_name     subdomain.my-website.com;

    rewrite ^(.*)$ https://some.otherwebsite.com/ permanent;

server {
        some-other-website9.com         www.some-other-website9.com
        some-other-website10.com         www.some-other-website10.com
        some-other-website11.com         www.some-other-website11.com

    rewrite ^(.*)$  https://www.my-website.com/ permanent;

I'm wondering if this bind() error is happening because of my config. Any ideas what I might be doing wrong? I'm using nginx/1.4.6 (Ubuntu). Any help would be greatly appreciated.

  • I'm currently facing the same issue. A once working nginx config with no changes now wont successfully reload as it is saying port in use, however nginx is the only app running on that port. Have you solved your issue?
    – Mitch Kent
    Aug 25 '15 at 12:02

Try stopping nginx:

service nginx stop

Check the nginx still running:

ps ax | grep nginx

And if still running, kill the process:

kill -p PID

Check nginx status, will not run:

ps ax | grep nginx

And then do a clean-start:

service nginx start

This worked for me after same issue.

  • 1
    For me, after killed the PID, the process will start itself again
    – Jason Liu
    Apr 21 '20 at 19:02

I had a similar issue.

This is what worked for me:
sudo fuser -k 80/tcp
service nginx restart

I dunno the cause, but my answer was found here: https://easyengine.io/tutorials/nginx/troubleshooting/emerg-bind-failed-98-address-already-in-use/

Also, here is the backstory of how/when this error message showed up: https://serverfault.com/a/939888/399723


According to your netstat output, nginx itself is still running on port 80.

Before you try to restart it, validate your configuration with nginx -t and fix the errors.

  • 4
    I have run nginx -t and there are no errors. That's why I'm confused by not being able to restart.
    – dallen
    Mar 14 '15 at 21:14
  • Try stopping nginx first, and then starting it again. Mar 14 '15 at 21:21
  • 1
    I rand into the same issue. I'd consider this a bug of nginx. Sep 17 '15 at 14:59

I'm probably the only one dumb enough to make this mistake, but I accidentally downloaded the wrong package (php instead of php-fpm), which installed Apache 2 as a dependency. Since it was running on port 80, Nginx couldn't.

Probably not a very common mistake, but I guess the takeaway is to check if you accidentally have anything else on port 80.

  • 1
    You aren't the first to do that. The package name was poorly chosen; it really should have been named mod_php instead. But now that it's been that way for years, it can't be changed without breaking everyone's system. Jun 6 '19 at 21:13
  • 1
    @MichaelHampton At least it's a fairly simple fix (apt-get remove apache2 && apt-get autoremove) Jun 6 '19 at 21:47

First, we have to check how many services run on port 80. To check that, you could run the following command:

sudo netstat -plant | grep 80

This would show you which service exactly is listening on port 80 and then you can make a decision whether you want to have that service as is or have Nginx instead.

If it is Apache, you will need to decide whether you want to use Apache or Nginx.

If you only want to have Nginx, you need to stop Apache first:

sudo systemctl stop apache2 && sudo systemctl start nginx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.