Ubuntu Gutsy - Installing Nginx from source

Nginx is a popular server for those who do not need the bulk and extra services that Apache may offer.

This article will look at installing Nginx from source on an Ubuntu Gutsy Slice.


Versions

At the time of writing, the latest stable version of Nginx is 0.5.33. You can check the latest versions and change logs at the main nginx site.

Do note that Nginx is also available from the aptitude repositories and is at version 0.5.26 if you install that way.

Although not a lot of difference between the versions, if you prefer using the latest and greatest, then installing from source in an option.

Dependencies

As we are not using the package manager to install nginx, we need to take care of some dependencies.

Not many are needed and include pcre, ssl and zlib packages:

sudo aptitude install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev

Download

Now we can download the source code. Move into your sources directory (if it doesn't exist then simply create it):

cd ~/sources/

And then download the source code:

wget http://sysoev.ru/nginx/nginx-0.5.33.tar.gz

Unpack

Unpack the downloaded tar file and move into the newly created directory:

tar -zxvf nginx-0.5.33.tar.gz
...
cd nginx-0.5.33/

Options

There are quite a few compile time options that are available to use.

Have a look at the Install Options page of the nginx wiki for full details.

We're going to use just two options to customise the install. The first of which is:

--sbin-path=/usr/local/sbin

By default, nginx will be installed in /usr/local/nginx which, although a good place, does mean the main nginx binary will be found in /usr/local/nginx/sbin/nginx.

Not a location we are likely to find in our default search paths. So instead of adding new directories to our path (which may cause errors later on) we simply define where to put the binary.

The second option is:

--with-http_ssl_module

Probably self explanatory, but this will enable the ssl module to be compiled so we can parse https requests.

Compile

Let's go ahead and compile nginx using those two options:

./configure --sbin-path=/usr/local/sbin --with-http_ssl_module

There will be a nice summary at the end of the compile which includes such items as:

...
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/sbin"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
...

Keep a note of the output as it does contain some useful paths and locations for various files.

Make

Ok, let's go ahead and 'make' and then 'make install':

make
...
sudo make install

Defaults

Done. We can test the install by starting nginx:

sudo /usr/local/sbin/nginx

and navigating to our Slice IP address (assuming you have no other server running):

http://123.45.67.890

You will be greeted with the standard welcome page:

Nginx Welcome Screen

Stop

If you have used Apache or some other web server, you may be used to using a script to start and stop it such as you might find in '/etc/init.d'.

Unfortunately, compiling from source does not create a script like that (the next article will deal with creating such a script).

You may have noticed that one of the paths noted in the compile summary was:

nginx pid file: "/usr/local/nginx/logs/nginx.pid"

Let's make use of that to stop nginx:

sudo kill `cat /usr/local/nginx/logs/nginx.pid`

That will use the output of the pid file to kill the nginx process - note the use of backslashes (`) and not single quotes (') in the command.

Summary

Although quite detailed, we have installed the latest version of nginx from source and compiled it with some custom options to make life slightly easier.

We also know how to start and stop nginx by hand. As mentioned, the next article will deal with creating an init script so we have more control over the server.

Once done, we will then look at configuring nginx, setting up vhosts and proxying to a backend (such as a cluster of mongrels).

PickledOnion.

Article Comments:

Tony commented Tue Feb 12 19:37:05 UTC 2008:

When using this method, how would you go about removing Nginx?

Ciaran Lee commented Wed Feb 20 04:06:09 UTC 2008:

Hi Tony, To uninstall you would run sudo make uninstall from the same directory that you installed from at the beginning.

Josh Deeden commented Tue Apr 22 21:59:07 UTC 2008:

There doesn't appear to be an 'uninstall' make target in the nginx 0.5.35 Makefile

Any other ideas for cleanly uninstalling from source?

eric commented Wed Oct 22 03:48:37 UTC 2008:

i installed nginx this way prior to installing php and fastCGI ... how can i uninstall the source.. any ideas?

rainbow hat seo commented Sat Mar 21 16:58:41 UTC 2009:

To uninstall:

rm -f -R /usr/local/nginx rm -f /usr/local/sbin/nginx

chloe burgess commented Wed Sep 14 07:37:59 UTC 2011:

this is blocking me from youtube, some games and more and i do not know how to get rid of it. This is not what i was expecting from nginx, it is very unusfull.

metta hansen commented Sun Jan 22 05:00:37 UTC 2012:

I never heard of nginx. I don't know how it got on my computer or what it is supposed to do, so I have no idea where to go to uninstall it, but it is doing me no good. It just keeps popping up with a blank welcome page. How do I get rid of it if I don't know where it came from? BTW: I am not a newbie, but I am not far advanced either. Computer terms just cross my eyes. Can you help?

metta hansen commented Sun Jan 22 05:00:42 UTC 2012:

I never heard of nginx. I don't know how it got on my computer or what it is supposed to do, so I have no idea where to go to uninstall it, but it is doing me no good. It just keeps popping up with a blank welcome page. How do I get rid of it if I don't know where it came from? BTW: I am not a newbie, but I am not far advanced either. Computer terms just cross my eyes. Can you help?

Polly commented Sun Mar 04 23:54:16 UTC 2012:

DO NOT WANT THIS NGINX. WHEN I CLICK ON FACEBOOK THIS STUPID PROGRAM COMES UP. DON'T KNOW WHERE IT CAME FROM BUT CERTAINLY WANT TO UNINSTALL IT. HOW DO I UNINSTALL IT???? VERY UPSET ABOUT THIS THING!!

mk-delta commented Tue Jun 05 21:31:34 UTC 2012:

polly,metta & chloe I think you are misunderstanding. In your case nginx is being used by the person administrating your network to cache websites you access, spy on you and block access to the sites that are against your organizations policy. it is not on your computer and you cannot get rid of it without accessing the proxy server. What you want to do is probably use tor or some local proxy to bypass the

lotfi commented Sun Jun 10 20:23:22 UTC 2012:

remove Nginx from register and everything will be well

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)