How To Install Nginx On CentOS 5/6/7 and Ubuntu server

Before Getting Start, Know About Nginx

Nginx is the world second most in use web servers/application in the world and uses most with the site which has higher web traffic sites of the world on the internet. Nginx is very much resource friendly web server application. Also, sometimes Nginx is used s a web server or a reverse proxy. Let’s install Nginx

In this tutorial, we’ll discuss how to get Nginx installed on your centOS 5/6/7 Ubuntu 14.04 server.

Step 1: Install EPEL Repository

EPEL stands for Extra Packages for Enterprise Linux. Because yum as a package manager does not include the latest version of Nginx in its default repository, installing EPEL will make sure that Nginx on CentOS stays up to date.
For CentOS 5/6/7 install EPEL, open terminal and type in:

#sudo yum install epel-release

Note: We don’t require and action to do for Ubuntu as Ubuntu team provides Nginx package in its default repositories

Step 2: Install Nginx

To install Nginx on Centos, open terminal and type in:

For CentOS

#sudo yum update
#sudo yum install nginx

After you answer yes to the prompt twice (the first time relates to importing the EPEL gpg-key), Nginx will finish installing on your virtual private server.

For Ubuntu

#sudo apt-get update
#sudo apt-get install nginx

Step 3: Start Nginx

Nginx does not start on its own. To get Nginx running, type:

On Centos

#sudo /etc/init.d/nginx start

On Ubuntu

Service will start Automatically.

Now, you can confirm that Nginx has installed on your Server/VPS by directing your browser to your IP address. You can run the following command to reveal your server’s IP address.

For CentOs

#ifconfig eth0 | grep inet | awk '{ print $2 }'

For Ubuntu

#ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Step 4: Check Nginx (Put Your Server's Ip Address)

On the page, you will see the words, “Welcome to Nginx”
Congratulations! You have now installed Nginx.

Nginx Welcome Screen |

Note : Default Nginx Installation Directory is /usr/share/nginx

Few Management Command For Nginx Process

To stop your Nginx:

#sudo service nginx stop

To start Nginx, type:

#sudo service nginx start

To restart the service again, type:

#sudo service nginx restart

Note: Management command for CentOs and Ubuntu are same.

To Restart automatically when the server is rebooted:

For Ubuntu

#sudo update-rc.d nginx defaults

This should already be enabled by default, so you may see a message like this:
System start/stop links for /etc/init.d/nginx already exist.

For CentOS

#chkconfig nginx on

Watch Video: And Subscribe To My YouTube Channel

Subscribe on Youtube

In case, if you are having anyone trouble in this tut please let me know by commenting and please share this article with your friends.

You May LIke to read:

Read How to Configure nginx with PHP in /var/www/html Directory