How to host multiple web sites on single server using Apache?
Ans : We can host multiple sites on single server. This can be done using multiple Virtual hosts with different host-names pointing to different directories in the server. In this post we taken two hosts to test this.
Step1 : check the package is installed or not
#rpm -qa | grep httpd
Step2 : Install the package
#yum install httpd
Step3 : For host based web access we require DNS server entries of our host.
Example host in this post is : server1.example.com(Actual server name) and hostbase1.example.com(our first virtual host name)
hostbase2.example.com(our second virtual host name)
So we have to give A record for the server1.example.com(192.168.0.1) then CNAME record for hostbase1.example.com and hostbase2.example.com which points to server1.example.com
Step3 : Create the root web directory and an index.html for this testing for both the virtual hosts.
I want to create my web directory in /hostnamebase1 for first virtual host and /hostbase2 for second virtual host
Now create index.html and try to write something which is meaning full in that file then save the file.
save and exit the file.
Now create index.html and try to write something in to that file then save the file.
save and exit the file.
Step4 : Now edit the httpd.config file
Step4(a) : Please specify the NameVirtualHost at any point in the file if this entry is not there or commented.
What is the significance of this entry?
Ans : This directive is set to IP address/actual system name if you want to configure your server to host name based virtual hosting. So here I am using IP address of my system. You can try to put actual host name if you want to test it.
Step4(b) : Now configure virtual host entry as shown below.
Go to last line and write the below content
Now For hostbase2
Save the file and exit.
Let me explain ServerName entry
ServerName hostbase1.example.com this is used to specify what is the virtual host name of your new Virtualhost. So user can type this FQDN to access this site.
Step5 : Check for the syntax errors in the httpd.conf file before restarting the apache service.
#httpd -k graceful
Step6 : Now start the service and then add it to booting scripts so that it will start automatically at every boot of the system
#service httpd restart
#chkconfig httpd on
Latest posts by Surendra Anne (see all)
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018
- Online training on Linux Bash shell scripting - February 8, 2018