Linux Virtual Web Hosting Configuration on CentOS / RHEL

How to configure the Linux Virtual Web Hosting on CentOS / RHEL / Scientific Linux (SL) / Oracle Linux (OL). Linux Virtual Web Hosting is a Configuration of multiple site on single Web server is called as Virtual hosting.Name Based Virutal Hosting is Hosting multiple sites on single lP is called as named based virtual hosting.Port Based is Hosting sites other than default port that is 80 is called as port based hosting.IP based Accessing a site on lP without using name is called as IP based hosting.

In this Tutorials we are going to host four examples sites:

  • www.techbrown.com
  • www.advancelinux.com
  • www.example.com
  • www.linux.com

Server Side Configuration

Step-1 (Check IP & Host Entries)
# ifconfig
Step-2 (Assigning a Virtual IP)
# netconfig --device eth0:1
On RHEL 6 based EL
# service network restart
On RHEL 7 based EL
# systemctl restart network
# ifconfig
# vi /etc/hosts
Add these entries for local resolution, so that we can check the web site from local webserver
127.0.0.1 localhost.localdomain localhost
192.168.0.X1 www.techbrown.com web.techbrown.com web
192.168.0.X1 www.advancelinux.com
l92.168.0.X1 www.example.com
192.l68.0.X2 www.linux.com

:wq!

Where X1 is a real IP
Where X2 is a virtual IP
Step-3 (Edit the Main Configuration File)
# vi /etc/httpd/conf/httpd.conf
############ NAME BASED ###################
NameVirtualHost l92.l68.0.X1:8O
<VirtualHost 192.168.0.X1:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/techbrown
ServerName www.techbrown.com
DirectoryIndex techbrown.html
</VirtuaHost>
<VirtualHost 192.168.0.X1:80>
ServerAdmin I [email protected]
DocumentRoot /var/www/html/advancelinux
ServerName www.advancelinux.com
DirectoryIndex advancelinux.html
</VirtuaIHost>
############# PORT BASED ######################
Listen 5000
<VirtualHost 192.168.0.X1:5000>
ServerAdmin [email protected]
DocumentRoot /var/www/html/example
ServerName www.example.com
DirectoryIndex example.html
</VirtualHost>
############ NAME BASED ######################
############ IP BASED ######################
<VirtualHost 192.168.0.X2:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/linux
ServerName www.linux.com
Directorylndex linux.html
</VirtualHost>

:wq!

To Authenticate Web server that is asking username & password for site www.advancelinux.com add this code at the end of configuration file.
# vi /etc/httpd/httpd.conf
<Directory /var/www/html/advancelinux>
AuthName "techbrownauth"
AuthUserFile /etc/httpd/conf/htpasswd
AuthType Basic
Require valid-user
</Directory>

:wq!

Step-4 (Create index or home html file in DocumentRoot folder that is /var/www/html)
Create DocumentRoot folder for each site
# cd /var/www/html
# mkdir techbrown advancelinux example linux
# cd
Create index or home html file respectively in their DocumentRoot folder.

Note: Similar to Step 4 of part one.

Step-5 (Create a user & provide web password to access www.advancelinux.com site)
# useradd gopal
# htpasswd -c /etc/httpd/conf/htpasswd gopal
Step-6 (Start the services)
On RHEL 6 based EL
# service httpd restart
On RHEL 7 based EL
# systemctl restart httpd
Step-7 (Open the Web Browser and type)
  • https://www.techbrown.com
  • http://www.advancelinux.com
  • http://www.example.com:5000
  • http://192.l68.0.X2

Client Side Configuration

Step-1 (Add the entry in /etc/hosts files)
# vi /etc/hosts
127.0.0.1 localhost.localdomain Iocalhost
192.168.0.Xl www.techbrown.com
192.168.0.X1 www.advancelinux.com
l92.168.0.X1 www.example.com
192.168.0.X2 www.linux.com

:wq!

Step-2 (Open the Web Browser & type)
# firefox &
  • https://www.techbrown.com
  • http://www.advancelinux.com
  • http://www.example.com:5000
  • http://l92.168.0.X2

Final Words

That’s all now you have installed and configured the Linux Virtual Web Hosting on CentOS / RHEL / Scientific Linux (SL) / Oracle Linux (OL) hope you now enjoy the multiple Linux Virtual Web Hosting with ease. For more information and support please use the comment section below.

Related Post

Develop New SysAdmin Skills with E-books (FREE Download)

COMMENTS