How to install nginx and install the configuration files too

51,461

Solution 1

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

Solution 2

first

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

then test

sudo nginx -t

Solution 3

sudo apt-get --purge autoremove nginx

If you are not prompted to prove successful uninstall

 which nginx

Solution 4

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

Solution 5

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/
Share:
51,461

Related videos on Youtube

MacMac
Author by

MacMac

Updated on September 18, 2022

Comments

  • MacMac
    MacMac over 1 year

    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
    MacMac over 12 years
    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
  • George Tasioulis
    George Tasioulis over 12 years
    Try apt-get install nginx-extras and restart nginx.
  • George Tasioulis
    George Tasioulis over 12 years
    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.
  • MacMac
    MacMac over 12 years
    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
  • George Tasioulis
    George Tasioulis over 12 years
    Nice :) So just do a cp /etc/mime.types /etc/nginx/mime.types and restart.
  • MacMac
    MacMac over 12 years
    I get this: Restarting nginx: [emerg]: unexpected end of file, expecting ";" or "}" in /etc/nginx/mime.types:822
  • MacMac
    MacMac over 12 years
    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).
  • FooBee
    FooBee over 9 years
    This doesn't answer the question.