Thursday, March 3, 2016

Setup of Nginx Vhost


This is an ancient way of setting up Vhost with nginx. As  we have Chef to automate everything. But before a kickoff with automation using chef, it’s crucial to interpret our problem statement by dealing with it manually.

Choose Older Eggs For Hard Cooking Maria Simmons

Problem Statement

NGINX is a free, open-source, high-performance HTTP server. Install nginx manually using package manager, and configure virtual host for,


This exercise consider that you have a basic understanding of Git, and Vagrant. This blog deal with centos7.

Install Nginx

Clone our github repository and spin up a bare centos7 vagrant machine.

Go to nginxVhost directory.

$ cd  Chef/centos/nginxVhost

  • This directory have a Vagrantfile. Which can initiate a centos7 vagrant box with 512mb ram.

$ cat Vagrantfile

This file update and install some basic tools in your vagrant machine using vagrant shell provisioning.

  • Launch new vagrant machine and login into it via ssh.
$ vagrant up

$ vagrant ssh

  • Add nginx repo
As nginx is not available in default list of centos7, we add nginx repo to it.

$ sudo yum install -y epel-release

  • Install nginx
Install nginx using package manager “yum”.

$ sudo yum install -y nginx

  • Start nginx
Nginx do not start on its own. Type following to start it.

$ sudo service nginx start

Setup Vhost

Let’s go ahead with our problem statement of setting up vhost with nginx. This leads some dull steps to serve our webpages with and

  • Replace nginx.conf file with given nginx.conf file.

$ sudo cp /vagrant/nginx.conf /etc/nginx/nginx.conf

  • Copy and into the /etc/nginx/conf.d directory
$ sudo cp /vagrant/ /etc/nginx/conf.d/

$ sudo cp /vagrant/ /etc/nginx/conf.d/

  • Create home directory for vhost.
$ sudo mkdir /usr/share/nginx/blog
$ sudo mkdir /usr/share/nginx/chef

  • Create index files.
$ sudo su -c "echo \"Welcome, this is\" > /usr/share/nginx/blog/index.html"
$ sudo su -c "echo \"Welcome, this is\" > /usr/share/nginx/chef/index.html"

  • Make entry in /etc/hosts
$ sudo vim /etc/hosts

  • Restart nginx server

$ sudo service nginx restart

  • Access and test your  Vhost

$ curl

$ curl
You have done all the tiring stuff to setup Nginx Vhost.

Don’t let a bad day make you feel like you have a bad life.

We understand your hard labour, so in next blog we go ahead to automate all the stuff.

1 comment:

Why I love pods in Kubernetes? Part - 1

When I began my journey of learning Kubernetes, I always thought why Kubernetes has made the pod its smallest entity, why not the container...