5

I keep on getting this error when trying to install nginx. I tried to reinstall it several times, but this error keeps on popping out and I can't start nginx.

Appreciate any help!

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
invoke-rc.d: initscript nginx, action "start" failed.
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-03-27 21:38:51 PHT; 10ms ago
  Process: 28178 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 28174 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

Mar 27 21:38:49 nico-Aspire-E5-575G nginx[28178]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 27 21:38:49 nico-Aspire-E5-575G nginx[28178]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 27 21:38:50 nico-Aspire-E5-575G nginx[28178]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 27 21:38:50 nico-Aspire-E5-575G nginx[28178]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 27 21:38:51 nico-Aspire-E5-575G nginx[28178]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 27 21:38:51 nico-Aspire-E5-575G nginx[28178]: nginx: [emerg] still could not bind()
Mar 27 21:38:51 nico-Aspire-E5-575G systemd[1]: nginx.service: Control process exited, code=exited status=1
Mar 27 21:38:51 nico-Aspire-E5-575G systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Mar 27 21:38:51 nico-Aspire-E5-575G systemd[1]: nginx.service: Unit entered failed state.
Mar 27 21:38:51 nico-Aspire-E5-575G systemd[1]: nginx.service: Failed with result 'exit-code'.
dpkg: error processing package nginx-core (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of nginx:
 nginx depends on nginx-core (>= 1.10.0-0ubuntu0.16.04.4) | nginx-full (>= 1.10.0-0ubuntu0.16.04.4) | nginx-light (>= 1.10.0-0ubuntu0.16.04.4) | nginx-extras (>= 1.10.0-0ubuntu0.16.04.4); however:
  Package nginx-core is not configured yet.
  Package nginx-full is not installed.
  Package nginx-light is not installed.
  Package nginx-extras is not installed.
 nginx depends on nginx-core (<< 1.10.0-0ubuntu0.16.04.4.1~) | nginx-full (<< 1.10.0-0ubuntu0.16.04.4.1~) | nginx-light (<< 1.10.0-0ubuntu0.16.04.4.1~) | nginx-extras (<< 1.10.0-0ubuntu0.16.04.4.1~); however:
  Package nginx-core is not configured yet.
  Package nginx-full is not installed.
  Package nginx-light is not installed.
  Package nginx-extras is not installed.

dpkg: error processing package nginx (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Errors were encountered while processing:
 nginx-core
 nginx
E: Sub-process /usr/bin/dpkg returned an error code (1)
  • 2
    looks like you are already using the same IP for another service? This message would point to something like that "Mar 27 21:38:49 nico-Aspire-E5-575G nginx[28178]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)" – Antonello Piemonte Mar 27 '17 at 14:12
8

Something is already running on port 80, so when nginx tries to start and take that port it fails. Check to see what is running on your port 80 and stop it. You can find out what is using port 80 with:

sudo netstat -lnp | grep 0.0.0.0:80

Once you find what is using the port, do a systemctl stop to stop it and try to start nginx again. Keep in mind that you will have to disable that other service permanently in order for nginx to work properly.

  • What if that command comes back empty? – Nathaniel Ford Jul 26 '17 at 1:10
  • 1
    @NathanielFord then it means that there is nothing listening on that port and that the problem is something else. – ddulic Jul 27 '17 at 17:54
  • 1
    The local ip need not be 0.0.0.0. On the Google compute engine I was using, it was :::80. Just drop the grep and read through the output nothing is running on 80/443. – notsopopularguy Aug 19 '17 at 11:35
2

It looks like NGINX and some other server app are both binding to use port 80 as their default port.

The easy solution would be to change the NGINX port to be something else, which can be done by editing /etc/nginx/sites-available/default (or whatever config file) to bind to a different port.

Look for a line that says something like this:

Listen 80;

Change the 80 to a free port (e.g. 851):

Listen 851;

Restart NGINX, and it should start up again without issue.

Note that if you want to actually use NGINX as your web host, you will need to change your other webserver's config.

2

The way I ended up in this same situation was by selecting a default option on Debian 9 during a virtual machine install on VirtualBox. I assume something similar may have happened to OP.

(...)
Choose software to install
[ ] Desktop environment
[*] Web Server
(...)

This will install Apache and enable/start its service right away. If your distro uses systemd you may check if that's the case:

sudo systemctl list-units | grep apache

Which shows:

apache2.service
      loaded active running   The Apache HTTP Server

You can stop the Apache service:

sudo systemctl stop apache2.service

And also disable de service so it doesn't restart automatically on next reboot:

sudo systemctl disable apache2.service

After that you may restart nginx:

sudo systemctl restart nginx

You may check that it's working with a command line browser such as Lynx:

lynx 127.0.0.1

                                    Apache2 Debian Default Page: It works (p1 of 4)
   Debian Logo Apache2 Debian Default Page
   It works!

   This is the default welcome page used to test the correct operation of the
   Apache2 server after installation on Debian systems. (...)

And you may find it weird/confusing that an Apache welcome page is still loaded by nginx. That's because Apache created a default html file which nginx is pointing to by default: /var/www/html/index.html. The default nginx html welcome file in my case was /var/www/html/index.nginx-debian.html. You may change which default page is loaded by modifying nginx default configuration file (and saving it with appropriate permissions):

sudo nano /etc/nginx/sites-available/default

(...)
# Default server configuration
#
server {
      (...)
      # original index directive:
      # index index.html index.htm index.nginx-debian.html;
      # modified index directive:
      index index.htm index.nginx-debian.html;
      (...)
}

By excluding index.html from the arguments to the index directive, the next candidate file is looked up. In my case index.htm doesn't exist, so index.nginx-debian.html is used. This change doesn't take effect until nginx is reloaded, so you may send it a reload signal:

sudo nginx -s reload.

And now you may check the default nginx welcome page:

lynx 127.0.0.1

                                                                 Welcome to nginx!
                                 Welcome to nginx!

   If you see this page, the nginx web server is successfully installed and
   working. Further configuration is required.
   (...)
  • 2
    Debian 9 is not Ubuntu, by the way. The same issues you're having in Debian don't apply to Ubuntu. – Thomas Ward Oct 24 '18 at 17:50
  • @ThomasWard thanks for the comment, I ended up reading about what should and shouldn't go into each specific SE site. I created this answer eagerly because it was right away the first google result for this problem. Do you mind deleting this answer? I would update it after testing on a Ubuntu system, but I'm just not sure when I would be able to do that. – arthropod Oct 25 '18 at 20:53
  • 1
    @arthropod this has been very helpful to me and I wouldn't think it necessary to delete such a good answer. While Debian and Ubuntu aren't exactly the same, the commonality dwarfs the difference. Creating a separate, likely hard-to-discover thread on Debian about the same issue would hardly be an improvement on things. – MichM Jan 21 at 18:19
0

Based in the error message:

  Package nginx-full is not installed.
  Package nginx-light is not installed.
  Package nginx-extras is not installed.

I recommend you to run sudo apt-get install nginx-full nginx-light nginx-extras

  • Irrelevant. The nginx meta-package has several alternate dependencies, as listed just two lines above those you quoted: nginx depends on nginx-core (>= 1.10.0-0ubuntu0.16.04.4) | nginx-full (>= 1.10.0-0ubuntu0.16.04.4) | nginx-light (>= 1.10.0-0ubuntu0.16.04.4) | nginx-extras (>= 1.10.0-0ubuntu0.16.04.4); however: Package nginx-core is not configured yet. nginx-common installs by itself, and should be enough to install nginx-core. – Urhixidur Aug 7 '17 at 18:00

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.