16

I've just completely uninstalled nginx 1.0.6 from my server (Ubuntu 11.04) using

apt-get remove nginx 
rm -rf /etc/nginx/
rm -rf /usr/sbin/nginx
rm /usr/share/man/man1/nginx.1.gz
apt-get remove nginx*

Now I want to install it again, however when starting nginx, I get errors such as:

Restarting nginx: nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)

Then I placed my own conf file, then I get a new error:

Restarting nginx: nginx: [emerg] open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /etc/nginx/nginx.conf:12

Now it seems that apt-get install nginx doesn't install it completely, I cleared the apt-get cache, doesn't seem to help. How can I get a full installation of nginx using apt-get?

5 Answers 5

33

Run apt-get remove --purge nginx nginx-full nginx-common first, and then apt-get install nginx and see if it works.

9
  • I get this: Starting nginx: nginx: [emerg] open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /etc/nginx/nginx.conf:12 nginx: configuration file /etc/nginx/nginx.conf test failed
    – MacMac
    Sep 30, 2011 at 10:59
  • Try apt-get install nginx-extras and restart nginx. Sep 30, 2011 at 11:07
  • Hmmm, I still get the same error above.
    – MacMac
    Sep 30, 2011 at 11:08
  • What is the output of locate mime.types? (run sudo updatedb first). Did the apt-get install nginx-extras do anything? Maybe you should try the commands on my initial answer, for the nginx-extras package too. Sep 30, 2011 at 11:11
  • I get this: /etc/mime.types /usr/share/doc/apache2.2-common/examples/apache2/mime.types.gz /usr/share/usermin/mime.types /usr/share/webmin/mime.types
    – MacMac
    Sep 30, 2011 at 11:19
8

first

sudo apt-get -o DPkg::options::=--force-confmiss --reinstall install nginx-common

then test

sudo nginx -t
0
3
sudo apt-get --purge autoremove nginx

If you are not prompted to prove successful uninstall

 which nginx
1

I had the same problem, and solved it by copying the configuration files from /opt/ into /etc/:

cp /opt/nginx/conf/nginx.conf /etc/nginx/
cp /opt/nginx/conf/mime.types /etc/nginx/
1

You first of all want to make sure that the older nginx is uninstalled completely together with its conf files.

 sudo service nginx stop
 sudo apt-get --purge autoremove nginx     
 sudo rm -rf /etc/nginx
 sudo rm /usr/sbin/nginx

Then install nginx. The nginx-extras comes in handy when you want to check your conf files for errors

 sudo apt-get install nginx nginx-extras

Then check whether your conf files are okay with the command;

 sudo nginx -t
1
  • This doesn't answer the question.
    – Sven
    Nov 20, 2014 at 15:46

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