virtual-web-hosting
Linux

Linux Virtual Web Hosting in Apache

0

Greeting guys in our new tutorial, last tutorial we have learnt how to configure basic level of web hosting server. This tutorial is also related to web hosting but we will learn how many types of web hosting and how to configure virtual web hosting in apache. Let’s move on World Wide Web;




Introduction

As we know that Apache is a powerful utility/ tool for web hosting server. You can host multiple web sites on a single Linux machine through virtual web hosting in Apache and you can change listen port as well by default apache (HTTP) listen 80. You can change or describe new port for web site.

Virtual Hosting is a technique of hosting on a single web server it may be apache, MS IIS, Nginix etc.

Types of Virtual Web Hosting

There are two types of virtual web hosting.

  1. Name based Virtual Hosting
  2. IP based Virtual Hosting

Name based Virtual Hosting

Name based hosting allows you to host more than one web site on a single IP with different domains/ web sites. It is very easy to configure than IP based virtual hosting. We need to configure DNS for deploy the Name based virtual hosting because DNS is the technique to handle/ control the domain name’s web site.

web server apache virtual hosting




IP based Virtual Hosting

IP based virtual hosting allows you to host only one domain/ web site on a single IP but you can add more than one Network Interface Card (NICs) in your web server or you can assign virtual IPs or by creating virtual NICs to host web site on particular IPs with in the one web server.

IP based virtual hosting

We are going to configure two virtual webs with different IPs and name based as well.

Scenario

For First Web                                                                                     For Second Web

IP = 192.168.4.2                                                                                 IP =192.168.4.3

URL = www.abc.com                                                                      URL = www.faa.com

Default port 80                                                                                  Port 8080

For the First Web

First you need to make a directory/ folder in /var/www/html/ by using command mkdir. Syntax mkdir path/dir-name

[root@faraz ~]# mkdir /var/www/html/abchost

Make a web file by using command touch. Here I am going to name that file as index.html.

[root@faraz ~]# touch index.html

Now open file by using command vi and here I am going to write some basic syntax of html for testing the virtual web hosting.

[root@faraz ~]# vi /var/www/html/abchost/index.html



 www.shahid-academy.com



Welcome Guys to Virtual Hosting

192.168.4.2%MINIFYHTML874dbc3e3b1949948f710876bf4ce6cf16%

For the Second Web

Repeat these steps with minor changes.

Make a directory/ folder in /var/www/html/ by using command mkdir for the second web. Syntax mkdir path/dir-name

[root@faraz ~]# mkdir /var/www/html/faa

Make a web file by using command touch. Here I am going to name that file as index.html.

[root@faraz ~]# touch index.html

Now open file by using command vi and here I am going to write some basic syntax of html for testing the virtual web hosting.

[root@faraz ~]# vi /var/www/html/faa/index.html



 www.shahid-academy.com



Welcome Guys to Virtual Hosting

192.168.4.3:8080 with port number

Permission and Ownership of hosting folders/ directories

Give them permission for user = all, group/ other = read & write.

[root@faraz ~]# chmod -R 755 /var/www/html/

Here ownership apache is for user and group by using chown command.

[root@faraz ~]# chown -R apache:apache /var/www/html/abchost/index.html
[root@faraz ~]# chown -R apache:apache /var/www/html/faa/index.html

Configuration in Apache (httpd. conf)

We are going to add/ make some parameters/ changes in httpd.conf file. Path of the configuration file is /etc/httpd/conf/httpd.conf. Now open it on a command line by using vi editor.

For the First Web

Make changes in Main Configuration area where are going define directives. By default it listens port is 80 and it is mention above of that area.

[root@faraz ~]# vi /etc/httpd/conf/httpd.conf

Listen 80



ServerName www.abc.com:80

ServerAlias www.abc.com

ServerAdmin academy@abc.com

DocumentRoot /var/www/html/abchost

CustomLog /var/log/httpd/abc.log combined

ErrorLog /var/log/httpd/abc.log.error

For the Second Web

Define port 8080 as well for access the site on that port.

[root@faraz ~]# vi /etc/httpd/conf/httpd.conf

Listen 8080



ServerName www.faa.com:8080

ServerAlias www.faa.com

ServerAdmin academy@faa.com

DocumentRoot /var/www/html/faa

CustomLog /var/log/httpd/faa.log combined

ErrorLog /var/log/httpd/faa.log.error

Outputs

Name Based

virtual host 2

virtual host 1

IP Based

In this tutorial we have learnt virtual hosting with name and IP based configuration. I hope you will easily understand this article and now a days virtual hosting is very popular for hosting the web sites.

ip based virtual hosting 1

ip based virtual hosting 2

 

Thanks

SUBSCRIBE OUR NEWSLETTER
Join us by subscribing to our newsletter and learn IT subjects for free
We hate spam. Your email address will not be sold or shared with anyone else.

Leave a reply

You must be logged in to post a comment.