Ubuntu Linux, ubuntu desktop, Linux operating system, ubuntu guide

Ngnix webserver Installation stpe by step from source

by on Mar.05, 2010, under Ngnix, Webserver

Nginx is a popular lightweight 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 a CentOS slice.


Versions

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

Building from source will allow you to have the latest available versions of Nginx. However, keep in mind that security updates will not be applied automatically.

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-devel zlib-devel and openssl-devel packages.

sudo yum install pcre-devel zlib-devel openssl-devel

Download

Now we can download the source code.

Create a ‘sources’ directory (you can download it anywhere you want to):

mkdir /ngnix

Now move into the folder:

cd /ngnix

And then download the source code:

wget http://nginx.org/download/nginx-0.7.65.tar.gz

Unpack

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

tar -zxvf nginx-0.7.65.tar.gz
...
cd nginx-0.7.65

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 customize 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

For more info

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://localhost

You will be greeted with the standard welcome page:

Nginx Welcome Screen

Stop

If you have used Apache or some other web server (or even installing Nginx via a package manager), 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 (we will create an init script in the next article or two).

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 backticks (`) and not single quotes (‘) in the command.


2 Comments for this entry

  • Merissa Phillips

    Many people like to know when they comment that someone is listening. The way to let them know that there is someone behind the computer screen who cares what they say is to respond when they say something.

  • Jered Heeschen

    Could you add a link to the original Slicehost article this was copied from, and include an attribution? Reposting is fine so long as credit is given. If a site administrator has any questions, feel free to email me at the address given when I posted this. Thanks!

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!