How to Install and Configure Nginx Web Server on CentOS 6.2

Share this Article :

Nginx or “engine x” is a free, open-source HTTP server and one of the alternative to Apache http server. It’s a high performance edge web server with the lowest memory footprint and the key features to build modern and efficient web infrastructure. In this post, i will guide you through the basic steps to install and configure Nginx web server on linux CentOS 6.2 server.

To add nginx yum repository, create a file named /etc/yum.repos.d/nginx.repo.

[root@centos62 ~]# vi /etc/yum.repos.d/nginx.repo

Paste one of the configurations below:

name=nginx repo

Install nginx using yum command :

[root@centos62 ~]# yum install nginx -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * rpmforge:
 * updates:
nginx                                                                        | 1.3 kB     00:00
nginx/primary                                                                | 3.0 kB     00:00
nginx                                                                                         17/17
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nginx.i686 0:1.0.12-1.el6 will be updated
---> Package nginx.i386 0:1.0.14-1.el6.ngx will be an update
--> Finished Dependency Resolution

Dependencies Resolved

 Package             Arch               Version                           Repository           Size
 nginx               i386               1.0.14-1.el6.ngx                  nginx               294 k

Transaction Summary
Upgrade       1 Package(s)

Total download size: 294 k
Downloading Packages:
nginx-1.0.14-1.el6.ngx.i386.rpm                                              | 294 kB     00:43
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : nginx-1.0.14-1.el6.ngx.i386                                                      1/2
  Cleanup    : nginx-1.0.12-1.el6.i686                                                          2/2

  nginx.i386 0:1.0.14-1.el6.ngx


Modify default website config file :

[root@centos62 ~]# vi /etc/nginx/conf.d/default.conf


 location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;

Edit as below :

 location / {
        #root   /usr/share/nginx/html;
        root   /var/www/html/nginxweb;
        index  index.html index.htm;

Create index.html :

[root@centos62 ~]# vi /var/www/html/nginxweb/index.html

Add this html code:

<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page for nginx web server

Start nginx web server :

[root@centos62 ~]# service nginx start

Leave a Reply