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?

MacMac
  • 2,061
  • 10
  • 31
  • 38

5 Answers5

36

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

womble
  • 96,255
  • 29
  • 175
  • 230
George Tasioulis
  • 2,019
  • 2
  • 17
  • 17
  • 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 '11 at 10:59
  • 1
    Try `apt-get install nginx-extras` and restart nginx. – George Tasioulis Sep 30 '11 at 11:07
  • Hmmm, I still get the same error above. – MacMac Sep 30 '11 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. – George Tasioulis Sep 30 '11 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 '11 at 11:19
  • Nice :) So just do a `cp /etc/mime.types /etc/nginx/mime.types` and restart. – George Tasioulis Sep 30 '11 at 11:34
  • I get this: `Restarting nginx: [emerg]: unexpected end of file, expecting ";" or "}" in /etc/nginx/mime.types:822` – MacMac Sep 30 '11 at 11:36
  • I've done it myself, thanks for the help you tried. I will post my answer in 6 hours (SF doesn't let me post in 6 hours). – MacMac Sep 30 '11 at 12:18
  • After 2 hours this answer help me reinstall manually removed nginx. Thanks. – M. Wiśnicki Feb 05 '17 at 00:13
8

first

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

then test

sudo nginx -t
Jenny D
  • 27,780
  • 21
  • 75
  • 114
upt
  • 81
  • 1
  • 1
3
sudo apt-get --purge autoremove nginx

If you are not prompted to prove successful uninstall

 which nginx
蔡正海
  • 131
  • 3
2

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
Komu
  • 381
  • 2
  • 6
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/
pjmorse
  • 1,550
  • 1
  • 17
  • 34