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.

[[email protected] ~]# vi /etc/yum.repos.d/nginx.repo

Paste one of the configurations below:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

Install nginx using yum command :

[[email protected] ~]# yum install nginx -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ipserverone.com
 * epel: ftp.yz.yamagata-u.ac.jp
 * extras: centos.ipserverone.com
 * rpmforge: apt.sw.be
 * updates: centos.ipserverone.com
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
====================================================================================================
Updating:
 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

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

Complete!

Modify default website config file :

[[email protected] ~]# vi /etc/nginx/conf.d/default.conf

Original

 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 :

[[email protected] ~]# vi /var/www/html/nginxweb/index.html

Add this html code:

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

Start nginx web server :

[[email protected] ~]# service nginx start

Leave a Reply