63
:~$ sudo apt-get remove nginx* && sudo apt-get install nginx-full*

Reading package lists... Done
Building dependency tree       
Reading state information... Done

After this operation, 5,579 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 nginx-full-dbg amd64 1.10.0-0ubuntu0.16.04.1 [3,789 kB]
Fetched 3,789 kB in 33s (112 kB/s)                                             
Selecting previously unselected package nginx-common.
(Reading database ... 189767 files and directories currently installed.)
Preparing to unpack .../nginx-common_1.10.0-0ubuntu0.16.04.1_all.deb ...
Unpacking nginx-common (1.10.0-0ubuntu0.16.04.1) ...
Selecting previously unselected package nginx-full.
Preparing to unpack .../nginx-full_1.10.0-0ubuntu0.16.04.1_amd64.deb ...
Unpacking nginx-full (1.10.0-0ubuntu0.16.04.1) ...
Selecting previously unselected package nginx-full-dbg.
Preparing to unpack .../nginx-full-dbg_1.10.0-0ubuntu0.16.04.1_amd64.deb ...
Unpacking nginx-full-dbg (1.10.0-0ubuntu0.16.04.1) ...
Processing triggers for ufw (0.35-0ubuntu1) ...
Rules updated for profile 'Apache Full'
Rules updated for profile 'Nginx HTTP'

Processing triggers for systemd (229-4ubuntu4) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up nginx-common (1.10.0-0ubuntu0.16.04.1) ...
Setting up nginx-full (1.10.0-0ubuntu0.16.04.1) ...
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.

dpkg: error processing package nginx-full (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of nginx-full-dbg:
 nginx-full-dbg depends on nginx-full (= 1.10.0-0ubuntu0.16.04.1); however:
  Package nginx-full is not configured yet.

dpkg: error processing package nginx-full-dbg (--configure):

 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.

                          Errors were encountered while processing:
 nginx-full

 nginx-full-dbg

E: Sub-process /usr/bin/dpkg returned an error code (1)
subodh007
  • 350
  • 2
  • 12
Mohit
  • 749
  • Try apt-get -f install without any package – Motte001 Apr 28 '16 at 09:49
  • already checked ,same error !!

    Please look:

    :~$ sudo apt-get -f install

    nginx-full-dbg depends on nginx-full (= 1.10.0-0ubuntu0.16.04.1); however: Package nginx-full is not configured yet.

    dpkg: error processing package nginx-full-dbg (--configure): dependency problems - leaving unconfigured Errors were encountered while processing:

    nginx-full nginx-full-dbg

    E: Sub-process /usr/bin/dpkg returned an error code (1)

    – Mohit Apr 28 '16 at 09:49
  • 1
    Do you have Apache installed and running on port 80 before you're installing nginx? Edit your question to include the output of systemctl -l status nginx as well – Thomas Ward Apr 29 '16 at 15:01
  • Did you have a different version of nginx installed as well? I see you ran a remove task, but if the older configurations are still around they may break the installation if they have deprecated commands or similar inlcuded. – Thomas Ward Apr 29 '16 at 15:06
  • See "systemctl status nginx.service" and "journalctl -xe" for details. – Can you please do that and include the output in your question? – David Foerster Apr 29 '16 at 17:41
  • Sorry Guys!!,Actually i found it that it was of apache error because it was using the port 80,now please tell me should i go for apache 2 uninstall or just installed on machine and stop the service when we install the Nginx. Now i have a different error like after uninstalling the apache2,it gives me all things(including nginx) installed except apache but still getting apache2 webpage while go for checking for nginx default page,Please help! – Mohit Apr 30 '16 at 10:32
  • and 1 more thing i am notice it that when we go for installation of phpmyadmin,before that tell me,Is phpmyadmin only uses apache service to run?,because i found that without installing apache server,on http://localhost it gives apache default page and on when we go for http://localhost/phpmyadmin,it gives like(as i told u on above message i installed LEMP;https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04):

    404 Not Found

    nginx/1.10.0 (Ubuntu)

    – Mohit Apr 30 '16 at 10:38
  • $ systemctl status nginx.service ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; ├─16289 nginx: master process /usr/sbin/nginx -g daemon on; master_process on ├─16290 nginx: worker process
    ├─16291 nginx: worker process
    ├─16292 nginx: worker process
    └─16293 nginx: worker process
    Presently nginx installed and gives status like this,thank you,Please help!!
    – Mohit Apr 30 '16 at 10:49
  • Could you please [edit] your post, when you want to add information? Especially file or program output listings (with the help of the {} button in the editor toolbar) are much more readable there; alternatively you can use a pastie service for longer listings and include the link of your pastie in your question. Overall it’s best to have everything relevant in one place. Additionally, comments may be deleted for various reasons. – David Foerster Jul 31 '16 at 14:45
  • There is perhaps an error in nginx config that prevents it from starting (or, e.g., an IP mentioned in nginx config is unavailable). Starting nginx became a part of installation process, apparently. – krio Apr 29 '16 at 18:56
  • sudo apt-get remove nginx* Careful! This DOES NOT do what you think it does. It is regexp so it matches any string containing ngin and I have just removed docker-engine accidentally. – Tony I. Apr 05 '17 at 11:01
  • Thanks for the suggestions above; apparently a LEB provider's default Ubuntu image pre-includes Apache, and has it running, for some weird reason. Had to uninstall (or at least stop/disable) Apache before I could install Nginx. – geerlingguy Nov 01 '18 at 03:24

9 Answers9

148

Shutting down apache2 first before installing nginx should fix this problem:

sudo service apache2 stop
Spl2nky
  • 113
  • 5
Andrew Chan
  • 1,481
  • 3
    Welcome to Ask Ubuntu! I recommend [edit]ing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.) – David Foerster Jul 31 '16 at 14:46
  • This gave me the hint I needed. In my case I was using a docker container which run another nginx server – mithril_knight Feb 15 '17 at 12:51
  • I hit the same thing, but finding the culprit with netstat -tulpn | grep :80, in my case it was Varnish configured to listen on port 80. systemctl stop varnish, then installing Nginx, fixed it for me. Why Debian/Ubuntu packages try to start themselves on install is beyond me... I would rather install, configure it how I like it, then start it :P – geerlingguy Jul 26 '17 at 13:57
  • It's odd that NGINX doesn't check for this in their installer, and at least provide a more helpful message. Apache is very commonly installed on Linux systems. – machineghost Oct 30 '19 at 23:52
  • Yes this works for me , but one should cross verify other process using the port 80 and stop it in order to install nginx – Sameer Kumar Choudhary May 07 '20 at 07:55
28

Andrew Chan provided the right answer for me. To extend his answer a bit, here's what you can do on the commandline;

stop apache2

sudo systemctl stop apache2.service

prevent apache2 to start at boot

sudo systemctl disable apache2.service

Reinstall nginx

sudo apt-get install nginx

  • 1
    I would suggest that you not disable Apache2 at boot if you need it - there are many cases where you do not need to disable Apache if you end up configuring it to listen on another port. Having done this myself, for some setups, I can speak from some experience (I also do a lot of work in the nginx package, which is where this experience comes from) – Thomas Ward Aug 02 '16 at 15:09
11

In my case the error is the server has IPv6 disabled. Solution:

Edit /etc/nginx/sites-enabled/default and comment IPv6 out:

listen [::]:80 default_server;

Reinstall nginx:

apt purge nginx
apt autoremove
apt install nginx
Videonauth
  • 33,355
  • 17
  • 105
  • 120
  • @DavidFoerster With apt 1.0, a new binary was introduced that collects many of the familiar (sub-)commands that were distributed among apt-get, apt-cache and so forth. For example, apt update equals apt-get update, apt search some-name equals apt-cache search some-name and so forth. In some cases, there has been some rewording, like apt full-upgrade that equals apt-get dist-upgrade. The old binaries and their commands are still available for those who fancy them, as well. – Henning Kockerbeck Oct 27 '16 at 15:04
  • @HenningKockerbeck: Thanks. I truly didn't know back then and thought it was a typo but I educated myself in the mean time. – David Foerster Oct 27 '16 at 17:51
  • Worked for me, but I can't implement this in my shell scripts for server deployment, that's ridiculously roundabout... – Menasheh Feb 15 '17 at 06:09
9

I just had this issue, but the solution was slightly different.

Once I solved a simple site misconfiguration, I was able to update nginx.

Check your nginx error log:

sudo cat /var/log/nginx/error.log|less

Then try again:

sudo apt-get update;sudo apt-get upgrade
Taiger
  • 109
2

In my case nothing helped at all, except of this:

sudo fuser -k 80/tcp

service nginx start
mansim
  • 121
1

Before the installation remove any manually added symlinks from /sites-enabled.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
Deto
  • 11
  • This was driving me crazy. I hadn't realised I had old sites in sites-enabled and had tried everything. I'm glad I scrolled to the bottom. – Michael Nov 21 '20 at 15:17
1

In my case it has been a misconfigurated file in /etc/nginx/sites-enabled/ I named them as .old files, but that does not matter. They will be readed and may prevend an successfull installation or start of that service. Be careful with files in that folder and read your error output carefully as discribed by @Taiger

Godot85
  • 11
1

When I checked /var/log/nginx/error.log I saw that the installer was unable to open /var/cache/nginx/microcache

A directory listing showed there was no /var/cache/nginx directory, so I created it and the install succeeded.

0

I see you want to reinstall Nginx, but we can have the same error when we have Nginx run in Docker container.

In this case, just look at started containers:

user@host:~$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             
STATUS              PORTS                                      NAMES
f4ee2264d5fb        docker_nginx        "nginx -g 'daemon of…"   5 months ago        Up 2 days           0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   nginx

Just stop it with CONTAINER ID

docker stop f4ee2264d5fb

Then you are able to install Nginx