This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
nginx is a high performance web server software. It is a much more flexible and lightweight program than apache.
The steps in this tutorial require the user to have root privileges. You can see how to set that up in the Initial Server Setup Tutorial in steps 3 and 4.
To install nginx, open terminal and type in:
sudo apt-get install nginx
When prompted, say yes. nginx is now installed on your virtual private server.
nginx does not start on its own. To get nginx running on your VPS, type:
sudo service nginx start
You can confirm that nginx has been installed as your web server by directing your browser to your IP address.
**You can run the following command to reveal your virtual server’s IP address.
ifconfig eth0 | grep inet | awk '{ print $2 }'
When you visit your IP address page in your browser, you will see the words, “Welcome to nginx”
You can see a screenshot of the utilitarian nginx welcome page here
To ensure that nginx will be up after reboots, it’s best to add it to the startup. Type this command into terminal:
update-rc.d nginx defaults
You may see a message like:
System start/stop links for /etc/init.d/nginx already exist.
If that is the case, then nginx is set up to run on startup, and you are all set.
Congratulations! You have now installed nginx
Once you have installed nginx on your virtual private server, you can do a variety of things on your server such as Set Up Virtual Hosts or Create an SSL certificate for your site
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
For the last step in setting up nginx to startup after reboots, you may need to install chkconfig first. sudo apt-get install chkconfig
Then proceed with the last two commands: sudo chkconfig --add nginx sudo chkconfig nginx on
So I’m stuck on installing it. I run sudo apt-get install nginx on my root user. It’s been spinning for several hours. Is it supposed to take this long?
How could I find the location of nginx.conf after installing nginx via sudo apt-get install nginx?
Good!!
Thanks!
Success
@martyaria: You can do it, but by default CPanel integrates with Apache. There are a number of plugins that will integrate with Nginx, but I don’t have any experience with those first hand.
is it possible to switch from Apache to Nginx on a Active server running Cpanel on Cent OS?
Thank you
@bilal.butter: Please pastebin nginx’s config file.
service nginx doesnot restart. i have tried many things but it does not give any error .But when i check confg files by nginx -t . i am getting this error. nginx: [emerg] “location” directive is not allowed here in /etc/nginx/sites-enabled/www.exapmle.com:30 nginx: configuration file /etc/nginx/nginx.conf test failed
Kindly help out
Thanks Kamal. Sorry for the late reply, totally forgotten that I asked this question.
Where should I add the code to? “/etc/nginx/sites-available/default” or “/etc/nginx/sites-available/wordpress”?
I tried adding to both, it didn’t work. Where should I be adding to, in those 2 files? I followed these 2 tutorials:
LEMP https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04
Wordpress https://www.digitalocean.com/community/articles/how-to-install-wordpress-with-nginx-on-ubuntu-12-04
Thank you!
I would recommend that you use the official nginx repository instead of the ubuntu source. It is maintained with the latest version verse 1.1.19.
http://nginx.org/en/linux_packages.html