How to install nginx and install the configuration files too
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/
Related videos on Youtube
MacMac
Updated on September 18, 2022Comments
-
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 over 12 yearsI 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 over 12 yearsTry
apt-get install nginx-extras
and restart nginx. -
George Tasioulis over 12 yearsWhat is the output of
locate mime.types
? (runsudo updatedb
first). Did theapt-get install nginx-extras
do anything? Maybe you should try the commands on my initial answer, for thenginx-extras
package too. -
MacMac over 12 yearsI 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 over 12 yearsNice :) So just do a
cp /etc/mime.types /etc/nginx/mime.types
and restart. -
MacMac over 12 yearsI get this:
Restarting nginx: [emerg]: unexpected end of file, expecting ";" or "}" in /etc/nginx/mime.types:822
-
MacMac over 12 yearsI'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 over 9 yearsThis doesn't answer the question.