Skip to main content

Setup of Nginx Vhost



Introduction

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 blog.opstree.com, chef.opstree.com.

Prerequisites

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 blog.opstree.com and chef.opstree.com.

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

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

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

$ sudo cp /vagrant/chef.opstree.com /etc/nginx/conf.d/chef.opstree.com

  • 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 blog.opstree.com\" > /usr/share/nginx/blog/index.html"
$ sudo su -c "echo \"Welcome, this is chef.opstree.com\" > /usr/share/nginx/chef/index.html"

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

127.0.0.1 blog.opstree.com
127.0.0.1 chef.opstree.com

  • Restart nginx server

$ sudo service nginx restart

  • Access and test your  Vhost

$ curl blog.opstree.com

$ curl  chef.opstree.com
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.




Comments

Post a Comment

Popular posts from this blog

EC2 Ssh Connection Refused

When ssh: connect to host ip_address port 22 Connection refused



Unable to access server???
Exactly when you see the error - “ssh: connect to host ip_address port 22: Connection refused” while connecting your AWS EC2 Instance. In order to find solution of the problem, you will go to AWS forum and other channels where you need to answers several questions first. But it's very difficult to find the actual problem. In order to get clues what the problem is, we should provide as many details as possible about what we have tried and the results we are getting. Because there are hundreds of reason why a server or service might not be accessible, also connectivity is one of the toughest issue to diagnose, especially when you are hosting something critical on your box. I've seen several topics on this problem, but none offers a solution to it.  I was not aware for what should I look at first. So I walk through from the very basics and investigated the following thing Use of verbose while ss…

jgit-flow maven plugin to Release Java Application

Introduction As a DevOps I need a smooth way to release the java application, so I compared two maven plugin that are used to release the java application and in the end I found that Jgit-flow plugin is far better than maven-release plugin on the basis of following points: Maven-release plugin creates .backup and release.properties files to your working directory which can be committed mistakenly, when they should not be. jgit-flow maven plugin doesn't create these files or any other file in your working directory.Maven-release plugin create two tags.Maven-release plugin does a build in the prepare goal and a build in the perform goal causing tests to run 2 times but jgit-flow maven plugin builds project once so tests run only once.If something goes wrong during the maven plugin execution, It become very tough to roll it back, on the other hand jgit-flow maven plugin makes all changes into the branch and if you want to roll back just delete that branch.jgit-flow maven plugin doesn…

VPC per envrionvment versus Single VPC for all environments

This blog talks about the two possible ways of hosting your infrastructure in Cloud, though it will be more close to hosting on AWS as it is a real life example but this problem can be applied to any cloud infrastructure set-up. I'm just sharing my thoughts and pros & cons of both approaches but I would love to hear from the people reading this blog about their take as well what do they think.


Before jumping right away into the real talk I would like to give a bit of background on how I come up with this blog, I was working with a client in managing his cloud infrastructure where we had 4 environments dev, QA, Pre Production and Production and each environment had close to 20 instances, apart from applications instances there were some admin instances as well such as Icinga for monitoring, logstash for consolidating logs, Graphite Server to view the logs, VPN server to manage access of people.




At this point we got into a discussion that whether the current infrastructure set-u…