How To Install nginx on Ubuntu 12.04 LTS (Precise Pangolin)

Published on May 31, 2012
How To Install nginx on Ubuntu 12.04 LTS (Precise Pangolin)

Status: Deprecated

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.

About nginx

nginx is a high performance web server software. It is a much more flexible and lightweight program than apache.

Set Up

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.

Step One—Install nginx

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.

Step Two—Start nginx

nginx does not start on its own. To get nginx running on your VPS, type:

sudo service nginx start

Step Three—RESULTS: Confirm That nginx Has Started

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

See More

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

By Etel Sverdlov

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

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!

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?




Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
June 18, 2014

@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

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
March 9, 2014

@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:

  1. LEMP https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04

  2. 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.


Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel