How to Install NGINX on CentOS, Redhat and Fedora

How to Install NGINX on CentOS, Redhat and Fedora

NGINX (Engine X) is a web server, Its getting popular very fast due to its fast speed. NGINX is also used as reverse proxy server. This tutorial will help you to setup NGINX on CentOS, Redhat 6/5 and Fedora Systems.

Step 1: Install Nginx

At the time of updating this article latest version of NGIX 1.6.0 is available under atomic repository for CentOS/Redhat 6/5. So first we need to add atomic repository in our system using following command.

# rpm -Uvh

Now use the following command to install NGINX web server on your CentOS/Redhat system.

# yum install nginx

Step 2: Nginx Basic Configuration

Do some initial setting before starting nginx. Edit Nginx main configuration file /etc/nginx/nginx.conf and update following values.

# vim /etc/nginx/nginx.conf

Update following values:

worker_processes  4;  # Number of CPU available in system.
listen  80;  # Port on which nginx will listen.

Step 3: Start Nginx Service

Use following commands to start Nginx web server and configure Nginx to auto start on system boot.

# service nginx start
# chkconfig nginx on

Now access your server on port 80 with your favorite browser, It will show default nginx page.

Step 4: Create First VirtualHost in NGINX

After making initial configuration changes in NGINX, let’s start with configuring first virtual host. Firstly create document root for your application

# mkdir -p /var/www/
# chown -R nginx.nginx /var/www/

Now create an index file with sample text

# echo "Welcome to NGINX" > /var/www/

Now create a virtual host configuration file. I just create a copy of default.conf file with name and edit file in editor.

# cp /etc/nginx/conf.d/virtual.conf /etc/nginx/conf.d/
# vim /etc/nginx/conf.d/

Make few changes in configuration file like below and keep other settings as it is.

server {
    listen       80;

    location / {
        root   /var/www/;
        index  index.html index.htm;


Finally restart NGINX service using following command

# service nginx restart

Congratulation’s! You have successfully installed Nginx. Read out other articles Install Nginx, MySQL, PHP (LEMP) Stack with PHP-FPM

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!

Enjoyed this video?
How to Install NGINX on CentOS, Redhat and Fedora
"No Thanks. Please Close This Box!"