Work With Apache HTTPD Virtual Host
What is HTTPD Virtual Host
Think if you have to host lots of website inside the same saver.you can not use /etc/httpd/conf/httpd.conf file.You need to distinguish each and every website separately.For this purpose there is option in apache httpd.This called virtual host.
There is separate folder for virtual host file located in
inside this folder you can create virtual host files with any name and .conf extension.We create separate conf file for to ease administration.
if you have followed previous tutorial then httpd manual also installed. otherwise install httpd-manual
sudo yum install httpd-manual
or you can use group install
yum groupinstall “Basic Web Server” -y
Navigate to server0.example.com/manual
then open configuration files
Open virtual host
There is sample virtual host example copy that
Change that as following
And also goto /etc/httpd/conf/httpd.conf and copy directory tag
Require all granted
Then the site1.conf file like this
Require all granted
After Creating or changing config file restart or reload the apache HTTPD server necessary.
We already add firewall permission to the http.
you can check firewall permission by
Then Create index.html file inside /var/www/site1/index.html
“This is site 1 ”
Then restart apache HTTPD server
Then this wont show any because of there is no dns record for site1.example.com
so lets add dns settings to /etc/hosts file.
Now lets navigate to site1.example.com because apache httpd is running on local host. site1 is working
now we create another site called site2
This is site2
copy site1.conf file and rename as site2.conf and change the content as follow
New host name is site2.example.com
add site2.example.com to /etc/hosts file
Check for syntax errors
restart apache httpd
systemctl restart httpd
now navigate to site2.example.com
Now site1.example.com and site2.example.com both website are running in same ip address.but website pointing by hostname.
Directory Block Directives
Have you noticed some statements inside the
Lets discuss about directory directives.
- AllowOverride None -This means .htaccess file can not execute any command if there is this directive
- Require all denied -This means httpd does not serve the content of that directory
- Require all granted -This means allow access to this directory and visitor can see the folder structure of the directory.
I hope you will learn something.if this artical helps you please share in facebook twitter google plus.
See you in Part 4
Have a Good Day