How to install and set up nginx on Ubuntu

Nginx-logo

Nginx (pronounced as “engine x”) is a high performance and a low memory usage web server. Apache is a process-based web server and nginx is an asynchronous web server.

As nginx wiki says,

“The main advantage of the asynchronous approach is scalability. In a process-based server, each simultaneous connection requires a thread which incurs significant overhead. An asynchronous server, on the other hand, is event-driven and handles requests in a single (or at least, very few) threads.

While a process-based server can often perform on par with an asynchronous server under light loads, under heavier loads they usually consume far too much RAM, which significantly degrades performance. Also, they degrade much faster on less powerful hardware or in a resource-restricted environment such as a VPS.

Pulling numbers from thin air for illustrative purposes: serving 10,000 simultaneous connections would probably only cause Nginx to use a few megabytes of RAM, while Apache would likely consume hundreds of megabytes (if it could do it at all).”

In other words, nginx needs less memory to run and can handle more simultaneous connections with less memory. This is great, especially if your server isn’t too powerful as mine. I have the 5 dollars/month plan at DigitalOcean so my VPS has only 512MB RAM. DigitalOcean gives cloud virtual servers with SSD discs at a very low price. Its an excellent service and with only 5 dollars I own a cloud server with 20GB disc and I can host many virtual hosts for me and for my friends without problem.

But with low memory I need a light and efficient web server so I decided to change from apache2 to nginx. I read at many blogs that apache is simpler from nginx. I found out that nginx needs 2-3 more steps to setup but its not that harder. After the setup there are no big differences. In fact I am happy with my choise. Nginx is really light, fast, easy to add a new virtual hosts and I have the confidence that my little VPS will handle the demand that my hosts even when they start to be more popular.

The thing that troubled me most was the absence of a full setup guide. So, I had to search a lot and read many different articles to learn how to setup nginx. I will try to gather all those informations to a single article hoping to help some of you. My VPS runs Ubuntu Server 12.04 but most things are the same for CentOS and maybe more Linux servers.

But enough talk. Lets start to install:

One thought on “How to install and set up nginx on Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *