How to install nginx in rhel and centos

Sarath Pillai's picture
installing nginx

Hi all..in the post how is nginx different from apache we discussed about the major factors which makes nginx different from apache.

In this post we will see how can we get the package nginx installed. We will be doing this installation tutorial in Red Hat Enterprise linux (configuring it in Centos is exactly the same.).

I will keep my post as simple as possible, please let me know about the shortcomings that you felt in this post. So lets start out tutorial.

Its recommended that you enable "epel" repo in your yum configuration files path inorder to install the nginx package through yum package manger.

Installing Nginx in Red Hat Enterprise Linux & Centos

 

Step 1:  Enabling the EPEL repo for nginx the package.

EPEL stands for Extra packages for Enterprise Linux. You can enable this repository for your yum package management by going to below URL's.

RHEL5/CentOs5 Epel Repo

RHEL6/CentOs5 Epel Repo

Install the epel repo package to enable the epel repo.

You can also add nginx repository to your yum config files, to install. But due to the large collection of dependency packages available with epel, i recommend installing from epel.

Nginx repository can be enabled by adding the urls mentioned in the official site Nginx Yum Repo

Step2: Installing Nginx through Yum

Installing nginx through yum is just a command away. and can be done as below.

[root@slashroot ~]# yum install nginx                                                                             

Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package nginx.i386 0:0.8.55-2.el5 set to be updated
--> Processing Dependency: libGeoIP.so.1 for package: nginx
--> Running transaction check
---> Package GeoIP.i386 0:1.4.8-1.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package          Arch            Version                 Repository       Size
================================================================================
Installing:
 nginx            i386            0.8.55-2.el5            epel            390 k
Installing for dependencies:
 GeoIP            i386            1.4.8-1.el5             epel            781 k

Transaction Summary
================================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 1.1 M
Is this ok [y/N]:

 

If you encounter dependency issues while installing through yum you can solve that by searching the dependency package or library file(with .so extension) in pkgs.org and then downloading and installing that package for your respective version of OS, by rpm command.

Installing Nginx from Source:

first of all download the source package from here

Now unzip the package by the following command.

[root@slashroot ~]# tar -xvf nginx-1.2.4.tar.gz
 

Now you will have a directory named nginx-1.2.4.tar.gz in the location where you unzipped the .gz package file.

/usr/local/nginx is the default installation directory of nginx.

Now lets get inside the directory which we unzipped.

[root@slashroot nginx-1.2.4]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README

 

Now lets configure our nginx installtion with ./configure command. There are many number of options available with this ./configure command, like the following.

--prefix  to override the default installation path of /usr/local/nginx

--sbin-path this option can be used to specify the nginx command path.

--pid-path    pid file path; like the files we have in /var/run/

--http-log-path      you can specigy the log file path with this option.

with these above mentioned options i can both mention the path of the files, and also the file names.

[root@slashroot nginx-1.2.4]# ./configure --prefix=/home/sarath/ --pid-path=/etc/nginx/nginx.pid --http-log-path=/var/log/nginx_access_log --with-pcre=/etc/nginx/pcre --with-zlib=/etc/nginx/zlib
 

Note:  the --with-pcre option i included sets the path for PCRE library, this library is used by nginx for rewrite rules. and regular expressions used in it. --with-zlib option is required because of the library required by nginx for compression. these packages needs to be downloaded http://www.pcre.org/ and http://www.zlib.net/ and unzipped in those locations we secified

If you do not need those functiionalities in your nginx installation, then you can ignore those by the option as below and configure it without them as below.

[root@slashroot nginx-1.2.4]# ./configure --prefix=/home/sarath/ --pid-path=/etc/nginx/nginx.pid --http-log-path=/var/log/nginx_access_log --without-http_rewrite_module --without-http_gzip_module
 

Now we will compile our selected options. by make command.

[root@slashroot nginx-1.2.4]# make
 

Now lets install it.

[root@slashroot nginx-1.2.4]# make install
 

Thats it you have installed nginx from source package.  Now lets start nginx with the below command.

[root@slashroot ~]# /home/sarath/sbin/nginx
 

I have installed it in /home/sarath which is the reason am using this path to start nginx.Lets confirm whether our nginx is running by the following command.

[root@slashroot ~]# lsof -i :80
COMMAND  PID   USER   FD   TYPE DEVICE SIZE NODE NAME
nginx   5850   root    6u  IPv4  52188       TCP *:http (LISTEN)
nginx   5890 nobody    6u  IPv4  52188       TCP *:http (LISTEN)

 

and also from the below command.

[root@slashroot ~]# ps aux | grep nginx
root      5850  0.0  0.1   2600   984 ?        Ss   10:00   0:00 nginx: master process /home/sarath/sbin/nginx
nobody    5890  0.0  0.1   2748   896 ?        S    10:01   0:00 nginx: worker process

 

Now lets see and compare if thats the pid written to the file we mentioned during our installation configuration option --pid-path option.

[root@slashroot ~]# cat /etc/nginx/nginx.pid
5850

 

 

We will be discussing the configuration of nginx in our next post.

Rate this article: 
Average: 3.5 (282 votes)

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.