What are virtual hosts ? and How to configure virtual hosts on centos 7

What are Virtual Hosts?

A virtual hosting platform may be shared by different users or dedicated to a website, application or customer. In a shared virtual host platform, a provider’s physical server compute and storage resources are shared by two or more subscribers.

How to configure virtual hosts on centos 7

Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web.

LET’S GET STARTED…………………………….

STEP 1:- INSTALL APACHE WEB SERVER

on CentOS/RHEL:
Sudo yum install httpd
on Ubuntu/ Debian:
sudo apt-get update
sudo apt-get install apache2

STEP 2:- CREATE DIRECTORY STRUCTURES AND ADD DEMO PAGE FOR VIRTUAL HOSTS

Apache server is using /var/www as a document root of static content Lets create a folder name inside this www directory
cd /var/www
sudo mkdir cloudsbabademo.com
sudo vi index.html
Add the below content in index.html
<!DOCTYPE html> 
<html> 
<head>
<title>welcome to cloudsbaba</title> 
</head>
<body> <h1>This is a Sample Page for Cloudsbabademo</h1> 
<p>This is sample paragraph for cloudsbabademo</p> 
</body>
</html>

STEP 3:- CREATE VIRTUAL HOSTS FILE

Virtual host files are what specify the configuration of our separate sites and dictate how the Apache web server will respond to various domain requests Create two directories sites-available and sites-enabled. sites-available directory will keep all of our virtual host files, while the sites-enabled directory will hold symbolic links to virtual hosts that we want to publish.
sudo mkdir /etc/httpd/sites-available 
sudo mkdir /etc/httpd/sites-enabled
Now we should tell apache that virtual host file is present in site-available directory by doing this
sudo vi /etc/httpd/conf/httpd.conf
Add below line at the end file
IncludeOptional sites-enabled/*.conf
save and exit Now create virtual Hosts File
sudo vi /etc/httpd/sites-available/cloudsbabademo.com.conf
add the below content
<VirtualHost *:80>
       ServerName www.cloudsbabademo.com
       ServerAlias cloudsbabademo.com
       DocumentRoot /var/www/cloudsbabademo.com/
       ErrorLog /var/www/cloudsbabademo.com/error.log
       CustomLog /var/www/cloudsbabademo.com/requests.log combined
</VirtualHost>

save and exit

STEP 4:- Enable New VIRTUAL SERVER FILES

we can create a symbolic link for each virtual host in the sites-enabled directory.
what is symbolic link?
A symbolic link, also known as a symlink or a soft link, is a special type of file that simply points to another file or directory just like shortcuts in Windows.
sudo ln -s /etc/httpd/sites-available/cloudsbabademo.com.conf /etc/httpd/sites-enabled/cloudsbabademo.com.conf
Restart the apache server
Sudo systemctl restart httpd

STEP 5:- Check Your Result

http://<yourdomainname>
Congratulations  you follow all the steps and configure virtual hosts on centos 7 for more updated kindly follow www.cloudsbaba.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts