Introduction : -
Shared Hosting or Virtual Hosting refers to a hosting service where more than one web site reside on the same server , each web site has its own space.
Apache Shared Hosting can be implementing in two ways :-
1- Apache IP-based virtual Hosting : - each web site should has its own IP address or web sites can share one IP address but with different PORT number (www.site1.com:8888 , www.site2.com:8889 ... ) .
2- Apache Name-based Virtual Hosting :- more than one web site can share the same IP address , that means all web sites in the DNS point to the same IP address and the apache takes care of redirect the requester to the correct site.
Example :-
x hosting company host six web sites ( www.site1.com , www.site2.com .... www.site6.com ) on the same server and each of them belong to different person.
Implementation :-
assume we have one server running solaris 10 and we want to host two web sites on this server .
Information :-
- First web Server IP :- 192.168.1.50
- Second web Server IP :- 192.168.1.51 (you need the second IP just if you want to implement IP-based Virtual host based on port number)
- first web site name :- site1.com
- second web site name :- site2.com
Steps :-
Note :- Clear cache storage in the web browser before test any changes .
- IP-based virtual host (case 1 :- each site has its own IP address )
➊ make sure the apache service is running on solaris 10 , at the prompt type :-
svcs -a | grep -i apache2
if the apache is running you will see the following : -
online 0:28:03 svc:/network/http:apache2
if the status is disabled ,
disable 0:28:03 svc:/network/http:apache2
enable it , at the command prompt type :-
svcadm enable apache2
➋ create directories that will hold site1 and site 2 files ,
cd /var/apache2/htdocs
mkdir site1 site2
cd site1
echo "Site1 Page">>index.html
cd ..
cd site2
echo "Site2 Page">>index.html
note that the "/var/apache2/htdocs is the DocumentRoot folder which holds all web sites files.
➌ Copy the file /etc/apache2/httpd.conf-example to /etc/apache2/httpd.conf by running the following command .
cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf
➍ edit the httpd.conf file as the following :-
vi /etc/apache2/httpd.conf
Follow the link to Configure basic apache setting :- Configure Apache on Solaris
scroll down until you reach Virtual Hosts section .
add the following information :-
<VirtualHost 192.168.1.50:80>
ServerName site1.com
ServerAdmin admin@site1.com
DocumentRoot /var/apache2/htdocs/site1
ErrorLog /var/apache2/logs/site1.error.log
Customlog /var/apache2/logs/site1.access.log combind
</VirtualHost>
<VirtualHost 192.168.1.55:80>
ServerName site2.com
ServerAdmin admin@site2.com
DocumentRoot /var/apache2/htdocs/site2
ErrorLog /var/apache2/logs/site2.error.log
CustomLog /var/aapche2/logs/site2.access.log
</VirtualHost>
➎ save and close the document.
➏ restart the apache service
svcadm restart apache2
now , you have completed the configuration , try to access the site1.com by its IP address by type 192.168.1.50 in the web browser , if you see Site1 Page then your configuration is OK , now try to access site2.com by type 192.168.1.55 in the web browser , you have to see Site2 Page.
if you want to access site1 and site2 by names add a recored in the DNS for site1 and site2 , if you don't have a DNS server you can do that from hosts file in the operating system as follow :-
↪ UNIX + Linux = edit /etc/hosts file and add a record for site1 and site2 as following :-
192.168.1.50 site1.com
192.168.1.55 site2.com
↪ Windows = edit C:\WINDOWS\system32\drivers\etc\hosts file and add a record for site1 and site as following :-
192.168.1.50 site1.com
192.168.1.55 site2.com
-IP-based virtual host ( case 2 :- web sites share one IP address with different PORT )
➊ clear all configuration in previous step .
➋ make sure the apache service is running on solaris 10 , at the prompt type :-
svcs -a | grep -i apache2
if the apache is running you will see the following : -
online 0:28:03 svc:/network/http:apache2
if the status is disabled ,
disable 0:28:03 svc:/network/http:apache2
enable it , at the command prompt type :-
svcadm enable apache2
➌ create directories that will hold site1 and site 2 files .
cd /var/apache2/htdocs
mkdir site1 site2
cd site1
echo "Site1 Page">>index.html
cd ..
cd site2
echo "Site2 Page">>index.html
note that the "/var/apache2/htdocs is the DocumentRoot folder witch holds all web sites files .
➍ Copy the file /etc/apache2/httpd.conf-example to /etc/apache2/httpd.conf by running the following command .
cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf
➎ edit the httpd.conf file as the following :-
vi /etc/apache2/httpd.conf
scroll down until you reach Listen Directive , add the following information :-
Listen 192.168.1.50:8081
Listen 192.168.1.50:8082
➏ scroll down until you reach Virtual Host section and ad the following :-
<VirtualHost 192.168.1.50:8081>
ServerName site1.com
ServerAdmin admin@site1.com
DocumentRoot /var/apache2/htdocs/site1
ErrorLog /var/apache2/logs/site1.error.log
Customlog /var/apache2/logs/site1.access.log combind
</VirtualHost>
<VirtualHost 192.168.1.50:8080>
ServerName site2.com
ServerAdmin admin@site2.com
DocumentRoot /var/apache2/htdocs/site2
ErrorLog /var/apache2/logs/site2.error.log
CustomLog /var/aapche2/logs/site2.access.log
</VirtualHost>
➐ save and close the document.
➑ restart the apache service
svcadm restart apache2
now , you have completed the configuration , try to access the site1.com by its IP address by type 192.168.1.50:8081 in the web browser , if you see Site1 Page then your configuration is OK .
now try to access site2.com by type 192.168.1.50:8080 in the web browser you have to see Site2 Page.
if you want to access site1 and site2 by names add a recored in the DNS for site1 and site2 , if you don't have a DNS server you can do that from hosts file in the operating system as follow :-
↪ UNIX + Linux = edit /etc/hosts file and add a record for site1 and site2 as following :-
192.168.1.50 site1.com
192.168.1.50 site2.com
↪ Windows = edit C:\WINDOWS\system32\drivers\etc\hosts file and add a record for site1 and site as following :-
192.168.1.50 site1.com
192.168.1.50 site2.com
in the browser type site1.com:8081 and site2.com:8080
- Name-Based Virtual Host
➊ clear all configuration in previous step .
➋ make sure the apache service is running on solaris 10 , at the prompt type :-
svcs -a | grep -i apache2
if the apache is running you will see the following : -
online 0:28:03 svc:/network/http:apache2
Copy the file /etc/apache2/httpd.conf-example to /etc/apache2/httpd.conf by running the following command .
cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf
➌ create directories that will hold site1 and site 2 files .
cd /var/apache2/htdocs
mkdir site1 site2
cd site1
echo "Site1 Page">>index.html
cd ..
cd site2
echo "Site2 Page">>index.html
➍ edit the httpd.conf file as the following :-
vi /etc/apache2/httpd.conf
➎ scroll down until you reach Virtual Host section and ad the following :- NameVirtualHost 192.168.1.50:80
<VirtualHost 192.168.1.50>
ServerName site1.com
ServerAdmin admin@site1.com
DocumentRoot /var/apache2/htdocs/site1
ErrorLog /var/apache2/logs/site1.error.log
Customlog /var/apache2/logs/site1.access.log combind
</VirtualHost>
<VirtualHost 192.168.1.50>
ServerName site2.com
ServerAdmin admin@site2.com
DocumentRoot /var/apache2/htdocs/site2
ErrorLog /var/apache2/logs/site2.error.log
CustomLog /var/aapche2/logs/site2.access.log
</VirtualHost>
➏ save and close the document.
➐ restart the apache service
svcadm restart apache2
if you want to access site1 and site2 by names add a recored in the DNS for site1 and site2 , if you don't have a DNS server you can do that from hosts file in the operating system as follow :-
↪ UNIX + Linux = edit /etc/hosts file and add a record for site1 and site2 as following :-
192.168.1.50 site1.com
192.168.1.50 site2.com
↪ Windows = edit C:\WINDOWS\system32\drivers\etc\hosts file and add a record for site1 and site as following :-
192.168.1.50 site1.com
192.168.1.50 site2.com
in the browser type site1.com and site2.com
2 comments:
Apache shared hosting provide virtual hosting to web site service and i this is very interesting post..you have described everything is very clearly..website hosting services
Best info on apache shared hosting, thanks
Web Design Company in Bangalore | web Development Company in Bangalore | Website Design Company in Bangalore | Website Designers in Bangalore
Post a Comment