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”
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.
This exercise considers that you have a basic understanding of Git, and Vagrant. This blog deal with centos7.
Clone our github repository and spin up a bare centos7 vagrant machine.
$ git clone email@example.com:OpsTree/Chef.git
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 using package manager “yum”.
$ sudo yum install -y nginx
Nginx do not start on its own. Type following to start it.
$ sudo service nginx start
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
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 set up Nginx Vhost.
“Don’t let a bad day make you feel like you have a bad life.”
We understand your hard labor, so in next blog we go ahead to automate all the stuff.
One thought on “Setup of Nginx Vhost”
This is awesome !!!