Nginx installation error in Ubuntu 16.04

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

sudo service apache2 stop

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


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

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

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

sudo fuser -k 80/tcp

service nginx start