Ubuntu LTS - installing nginx

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

Unfortunately, nginx is not in the standard (officially supported) repositories that Ubuntu LTS (Dapper) uses. As such, let's look at installing nginx from source.


Versions

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

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 and ssl libraries:

sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev

Download

Now we can download the source code. Move into your sources directory:

cd ~/sources/

And then download the source code:

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

Unpack

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

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

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, nginx doesn't come with 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:

CLIdiot commented Wed Oct 17 17:32:20 UTC 2007:

any reason why this same set of instructions wouldn't work on Debian?

Paul Tomes commented Thu Oct 18 08:24:40 UTC 2007:

Hi,

Without error messages I am not sure. I'll be extending the nginx series to cover Feisty and Etch so I'll see more then.

It does seem a little odd though.

PickledOnion.

Ben commented Thu Nov 01 20:15:54 UTC 2007:

Great article. Thank you! The one thing this doesn't address is that the ubuntu package is compiled with specific options. I expect that a number of people will be moving from the package to the source because the lack of SSL functionality, so it would be cool if we could compile it the same way. I have yet to figure out the exact compile options they used...

-Ben

-Ben

Šime commented Mon Nov 12 20:41:17 UTC 2007:

I also installed zlib libs for gzip support. And I haven't bothered altering the sbin path because I always control it via init script so it doesn’t have to be in my path. I just leave it all in its self-contained /usr/local/nginx prefix.

Jon Leighton commented Tue Jan 08 14:51:27 UTC 2008:

I configured it to use slightly more standard locations with this concoction:

./configure --prefix=/usr/local --with-http_ssl_module --conf-path=/etc/nginx/nginx.conf --pid-path=/var/nginx/nginx.pid --lock-path=/var/nginx/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/nginx/client_body_temp --http-proxy-temp-path=/var/nginx/proxy_temp --http-fastcgi-temp-path=/var/nginx/fastcgi_temp

The default config file is then wrong though, you have to change include conf/mime.types to include /etc/nginx/mime.types and away you go.

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)