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

Kapendra Singh
3 min readMar 3, 2023

--

Originally published at https://kapendra.com

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

http://192.168.1.110 (Put Your Server's Ip Address)

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

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

You May LIke to read:

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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Kapendra Singh
Kapendra Singh

Written by Kapendra Singh

Love to write technical stuff with personal experience as I am working as a Senior DevOps Specialist. and believe in “every day is a learning day”

No responses yet

Write a response