How To Install Nginx with /var/www/html in CentOS 5/6/7 and Ubuntu 14.04 server
Linux Tutorials Web Servers

How To Install Nginx with /var/www/html in 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. It is used for most of the websites which have higher web traffic in the world on the internet. Nginx is very much resource friendly web server application. Also, sometimes Nginx is used as a web server or a reverse proxy. Let’s install Nginx

Let’s Start

In this tutorial, we’ll discuss how to get Nginx installed on your centOS 5/6/7 Ubuntu Server within /var/www/html.


My Server IP:
OS: CentOS 5/6/7 and Ubuntu

Note: If you are a SUDO user then prefix every command with sudo, like #sudo ifconfig

Step 1: Install EPEL Repository

Installing EPEL will make sure that Nginx on CentOS stays up to date. Install EPEL, open terminal and type following command

For CentOS 5/6/7:

Note: We don’t require any action 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:

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

Step 3: Nginx Default Configuration Changes

Now We Will Configure Nginx configuration file to map or Nginx server with /var/www/html. To Do this copy and paste under given configuration into the file /etc/nginx/nginx.conf

Edit file using vim Editor

Copy paste this configuration in this file and save it.

After writing content in the file, save and quit the file using :wq!

Step 4: Remove Default Configurations

Now remove Default file because we have made our single configuration file

Step 5: Create File in /var/www/html Directory

Now All we have to do create our HTML directory and a file with ‘.html’ extension with the help of following commands.

After writing content in the file, save and quit the file using :wq!

Step 6: Start Nginx

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

On Ubuntu

Service will start Automatically.

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

For CentOs

For Ubuntu

Step 7: Check Nginx (Put Your Server’s Ip Address)

On the page, you will see the words, “Hello I am in /var/www/html dir

Love to write technical stuff with personal experience as I am working as a Sr. Linux Admin. and every day is a learning day and Trust me being tech geek is really cool.

Leave a Reply