This article is deprecated and no longer maintained.
Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates.
This article may still be useful as a reference, but may not follow best practices or work on this or other Ubuntu releases. We strongly recommend using a recent article written for the version of Ubuntu you are using.
If you are currently operating a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
Nginx is a free, Open Source Web server. It is much more lightweight than Apache and it can be used as the main web server software or be set up as a reverse proxy for Apache.
Before using this tutorial, you will need to SSH into your VPS, by typing into the terminal: ssh <user>@<server_ip>. The user will need to either be in root or have root privileges, otherwise the commands entered below may not work.
The packages that you will need to install are python-software-properties and software-properties-common (which is only necessary if you are running Ubuntu 12.10).
To install the first package dependency, python-software-properties, you will need to run the following command:
sudo apt-get install python-software-properties
If you are on Ubuntu 12.10, you should run the following command to install software-properties-common, which is another package that is necessary (without it, the add-apt-repository command used in Step Two will not be found).
sudo apt-get install software-properties-common
To ensure that our web server software is secure to run on a VPS, we will be using the latest ‘stable’ release.
If you are developing a nginx module, or if you need to use the “bleeding edge” version, you can replace the ‘stable’ version with the ‘development’ version. However I would not recommend doing this on a VPS, as there may be bugs.
Now that we have the latest stable package installed, we can now add the repository to install the latest version of nginx:
sudo add-apt-repository ppa:nginx/stable
Note: If this command still does not work (normally on 12.10), run the following command:
sudo apt-get install software-properties-common
This will add the repository to Ubuntu and fetches the repository’s key. This is to verify that the packages have not been interfered with since they have been built.
After adding a new repository, you will need to update the list:
sudo apt-get update
To install nginx or update the version you already have installed, run the following command:
sudo apt-get install nginx
You can check to see that nginx is running by either going to your VPS’ IP address/domain, or typing in:
service nginx status
This will tell you whether nginx is currently running.
If nginx is not running correctly, and/or prints out an error e.g. nginx: [emerg] bind() to [::]:80 failed (98: Address already in use), you can run:
netstat -tulpn
This will list all processes listening on ports. You should see something like this:
The highlighted number, the PID, is the number that you will use to kill the process. In this case, you would need to run kill -9 734. However the general code to copy into your terminal would be:
kill -9 xxxx
The phrase, “xxxx”, is the PID of the process you want to kill. After killing the process, you can try restarting nginx again by running:
service nginx start
Alternatively, the issue may be caused by the configuration accepting connections from both ipv4 and ipv6. In order to resolve this, edit out “listen [::]:80” in your default config file (/etc/nginx/sites-available/default) and any other server block config files that are in use.
sudo nano /etc/nginx/sites-available/default
The lines should look like this:
server {
listen 80;
#listen [::]:80 default_server;
You can view more information about the PPA release from: https://launchpad.net/~nginx/+archive/stable
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!
I have updated using this tutorial, but I can not reload or restart nginx now. As a result I can not change some settings, like enable gzip. Nginx itself is somehow running and serving my website. Complete server Restart didn’t solve the problem. Any suggestions?
When i upgrade to 1.6.2 some things stop working like this https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-with-nginx-on-an-ubuntu-14-04-server
@Adriano: Yes, the same commands should work just fine.
Can I update nginx to its latest version if I’m on ubuntu 12.04 LTS?
Txt in advance!
Did a little searching: http://www.slashgeek.net/2013/05/08/how-to-get-the-latest-nginx-on-ubuntu-12-04-2-lts-precise-pangolin/
Running through this now to see how it goes
I’m trying to update nginx on my server (it’s at 1.1.19) and I know that it can be at 1.4.4 at least. I ran through the steps and it’s telling me it’s the latest version, even though it’s still at 1.1.19.
Is there something I’m missing? I’m on Ubuntu 12.04.3
Thanks, leo! I’ve had nginx 1.2.1 on Ubuntu 12.10. I’ve done: apt-get remove nginx-full nginx and then: apt-get install nginx-full and everything is working fine now.
Just a heads up… dunno why my ubuntu came with nginx 1.2 installed… i had to remove nginx-full to install the new version…
@jijo: Are you sure you removed apache? Try running <pre>sudo apt-get remove apache2*</pre>
Rebooted. Still Apache appears. :/