Learn how to install lightweight Nginx web server on UNIX environment.

Nginx was released in August 2002 and quite famous these days. Nginx hold 15.11% of market share in web server industry as of September, 2013.  In this article, I will talk about how to install nginx 1.4.3 (stable version as of October, 2013) on Unix using pre-built package and source code.

In this guide, I am using CentOS 6 and nginx 1.4.3 package. Instructions remain same for RHEL.

Installation using pre-built package

Nginx provides pre-built package for RHEL, CentOS, which you can download, and install using yum command.

  • Download latest stable yum repository
  • Install downloaded yum repository
rpm –ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

[/home/chandan/Downloads] #yum install nginx-release-centos-6-0.el6.ngx.noarch.rpm
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile *
base: mirrors.sin3.sg.voxel.net *
epel: mirror.nus.edu.sg *
extras: mirrors.sin3.sg.voxel.net *
updates: centos.ipserverone.com
Setting up Install Process
Examining nginx-release-centos-6-0.el6.ngx.noarch.rpm: nginx-release-centos-6-0.el6.ngx.noarch
Marking nginx-release-centos-6-0.el6.ngx.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package nginx-release-centos.noarch 0:6-0.el6.ngx will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package          Arch   Version            Repository                               Size ================================================================================
Installing: nginx-release-centos             noarch 6-0.el6.ngx /nginx-release-centos-6-0.el6.ngx.noarch 1.5 k Transaction Summary ================================================================================
Install               1 Package(s) Total size: 1.5 k Installed size: 1.5 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug Running
Transaction Test Transaction
Test Succeeded
Running Transaction 
Installing : nginx-release-centos-6-0.el6.ngx.noarch                        1/1 
Verifying  : nginx-release-centos-6-0.el6.ngx.noarch                      1/1 Installed:  nginx-release-centos.noarch 0:6-0.el6.ngx                                     
Complete!
  • Now, run following to install nginx
yum install nginx  

[/home/chandan/Downloads] #yum install nginx
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile *
base: mirrors.sin3.sg.voxel.net *
epel: mirror-fpt-telecom.fpt.net *
extras: mirrors.sin3.sg.voxel.net *
updates: centos.mirror.uber.com.au
nginx                                                   | 2.9 kB            00:00  
nginx/primary_db                                            |  25 kB            00:00  
Setting up Install Process
Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 0:1.4.3-1.el6.ngx will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package          Arch                Version                       Repository       Size ================================================================================
Installing: nginx               x86_64            1.4.3-1.el6.ngx            nginx               311 k Transaction Summary ================================================================================
Install               1 Package(s) Total download size: 311 k Installed size: 770 k
Is this ok [y/N]: y
Downloading Packages: nginx-1.4.3-1.el6.ngx.x86_64.rpm                              | 311 kB           00:00   Running rpm_check_debug
Running Transaction
Test Transaction
Test Succeeded
Running Transaction  Installing : nginx-1.4.3-1.el6.ngx.x86_64
1/1 ----------------------------------------------------------------------
Thanks for using nginx! Please find the official documentation for nginx here: * http://nginx.org/en/docs/ Commercial subscriptions for nginx are available on: * http://nginx.com/products/ ----------------------------------------------------------------------  Verifying  : nginx-1.4.3-1.el6.ngx.x86_64                                         1/1 Installed:  nginx.x86_64 0:1.4.3-1.el6.ngx
Complete!

Boom – nginx is installed now! You can find nginx configuration and binary as following.

Configuration – /etc/nginx

Binary – /usr/sbin/nginx

Document Root – /usr/share/nginx

Installation using source code

If you are working on DMZ server where you don’t’ have direct Internet connectivity to install pre-buillt package. It becomes crucial to know how to install using source code.

nginx-1.4.3.tar.gz
  • Extract the downloaded file
gunzip –c nginx-1.4.3.tar.gz | tar xvf –
  • After extract, you should see following files and folders
[/home/chandan/Downloads/nginx-1.4.3] #ls -ltr -rw-r--r--. 1 1001 1001           49 Oct  8 20:07 README -rw-r--r--. 1 1001 1001   1397 Oct  8 20:07 LICENSE -rwxr-xr-x. 1 1001 1001   2369 Oct  8 20:07 configure -rw-r--r--. 1 1001 1001 339761 Oct  8 20:07 CHANGES.ru -rw-r--r--. 1 1001 1001 223077 Oct  8 20:07 CHANGES drwxr-xr-x. 2 1001 1001   4096 Oct 15 13:35 man drwxr-xr-x. 8 1001 1001   4096 Oct 15 13:35 src drwxr-xr-x. 2 1001 1001   4096 Oct 15 13:35 html drwxr-xr-x. 3 1001 1001   4096 Oct 15 13:35 contrib drwxr-xr-x. 2 1001 1001   4096 Oct 15 13:35 conf drwxr-xr-x. 6 1001 1001   4096 Oct 15 13:35 auto [/home/chandan/Downloads/nginx-1.4.3] #

Now, we are ready to configure and install it. You can control installation location using –prefix=path parameter. Let’s install under /opt/nginx with ssl module.

./configure --prefix=/opt/nginx --with-http_ssl_module make make install

Upon completion, you should see nginx is installed under /opt/nginx with following folders.

[/opt/nginx] #ls -ltr drwxr-xr-x. 2 root root 4096 Oct 15 14:28 sbin drwxr-xr-x. 2 root root 4096 Oct 15 14:28 conf drwxr-xr-x. 2 root root 4096 Oct 15 14:28 logs drwxr-xr-x. 2 root root 4096 Oct 15 14:28 html [/opt/nginx] #

Congratulation, You have just installed nginx!

Stop and start procedure

To start:

Go to sbin folder and execute nginx

./nginx

To stop:

Go to sbin folder and execute

./nginx –s stop

I hope above quick installation guide helps you installing Nginx on Linux environment.

Reader Interactions

Comments

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