IP Based Virtual Web Hosting – PART 6

IP Based Virtual Web Hosting on Apache

IP-based virtual hosting is a method, which have a more than one IP address/Port assigned to your server and that receiving the request on it.

In our demonstration (shown below screen shot), a server could be receiving requests for different two domains(i.e ittroubleshooter1.in and ittroubleshooter2.in) both of which resolve to the different IP Addresses.

 

 

ip_virtual_host_c_ittroubleshooter-in

 

Previously we have seen various articles related to Apache Web server, refer below links;

Setting up Simple Web Server on RHEL7/Centos7

Create An Alias Web Site on Apache Web Server

Redirect the Website on Apache Web server

Port based hosting on Apache Web server

Name Based Virtual Web Hosting on Apache

Steps to configure IP based web hosting

1) Make a directories and create html files for IP based Web hosting.

In our demonstration we are creating two directories for IP based web hosting in document root (i.e /var/www/).

[root@server1 ~]# cd /var/www/
[root@server1 www]# mkdir ittroubleshooter1
[root@server1 www]# mkdir ittroubleshooter2
[root@server1 www]#

Go to “ittroubleshooter1” directory and create an index.html file.

[root@server1 www]# cd ittroubleshooter1
[root@server1 ittroubleshooter1]# vim index.html

Edit index.html file #vim index.html

<html> 
 <body> 
 <h1>Welcome to ITTroubleshooter1 Site</h1> 
###### IP Based Web Hosting #### 
</body> 
 </html>

~
~
:wq

Similarly, we create the index.html file in “ittroubleshooter2” directory.

[root@server1 ittroubleshooter1]# cd ../ittroubleshooter2
[root@server1 ittroubleshooter2]# vim index.html
<html> 
 <body> 
 <h1>Welcome to ITTroubleshooter2 Site</h1> 
###### IP Based Web Hosting #### 
</body> 
 </html>

~
~
:wq

Check the context using below command for both index.html files.

[root@server1 ~]# ls -Z /var/www/ittroubleshooter1/index.html 
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/ittroubleshooter1/index.html
[root@server1 ~]# ls -Z /var/www/ittroubleshooter2/index.html 
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/ittroubleshooter2/index.html
[root@server1 ~]#

2) Create Multiple IP Addresses to One Single Network Interface.

In our demonstration, We are using two IP Addresses on one single network interface to setup the IP based hosting on the server. If you don’t know how to create multiple IP’s on single NIC, refer below link.

Setting up Multiple IP Addresses To Single NIC Card on RHEL7/Centos7/Fedora22

Otherwise, If you have multiple NIC card then you can also assign the IP Addresses for multiple cards.

2) Edit the configuration file.

Navigate to ““/etc/httpd/conf.d”” directory, We already created (On previous articles) the  “ittroubleshooter.conf” file  and add a some lines on bottom, as shown below;

[root@server1 ~]# cd /etc/httpd/conf.d/
[root@server1 conf.d]# vim ittroubleshooter.conf

Edit ittroubleshooter.conf file # vim ittroubleshooter.conf

######## IP Based Hosting ##########
<VirtualHost 192.168.1.100:80>
ServerName www.ittroubleshooter1.in
DocumentRoot /var/www/ittroubleshooter1
ErrorLog logs/ittroubleshooter1.in-error_log
CustomLog logs/ittroubleshooter1.in-access_log common
</VirtualHost>

<VirtualHost 192.168.1.200:80>
ServerName www.ittroubleshooter2.in
DocumentRoot /var/www/ittroubleshooter2
ErrorLog logs/ittroubleshooter2.in-error_log
CustomLog logs/ittroubleshooter2.in-access_log common
</VirtualHost>

~                                                                                                                                                 
~         
:wq

Now, If you want translate from domain name to IP mapping add the Entries to the “/etc/hosts” file of the server, as shown below.

192.168.1.100   ittroubleshooter1.in
192.168.1.200   ittroubleshooter2.in

~     
~
:wq

finally check the syntax, using below command.

[root@server1 ~]# httpd -t
 Syntax OK
 [root@server1 ~]#

3) Restart the Apache service.

[root@server1 ~]# systemctl restart httpd
[root@server1 ~]#

4)Open the web browser and type the following url.

ipbasedhttpd_ittroubleshooter-in

 

ipbasedhttpd2_ittroubleshooter-in

To open the website from command line use the following command.

#elinks ittroubleshooter1.in

elinksipbased_ittroubleshooter-in

Hope this post will help Linux/Unix beginners. Please share you feedback and Comments. Till then connected with us at ittroubleshooter.in .!!!

Leave a Reply

1 Comment on "IP Based Virtual Web Hosting – PART 6"

Notify of
avatar
Sort by:   newest | oldest | most voted
هاست
Guest

thanks man

wpDiscuz