• Home
  • RHCE Work With Apache HTTPD Web Service Part 3- Work With Apache HTTPD Virtual Host -Dev Ops Lanka

RHCE Work With Apache HTTPD Web Service Part 3- Work With Apache HTTPD Virtual Host -Dev Ops Lanka

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

/etc/httpd/conf.d/

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

<VirtualHost *:80>

DocumentRoot “/var/www/site1”
ServerName site1.example.com
ErrorLog “site1-error_log”
TransferLog “site1-access_log”

 

</VirtualHost>

And also goto /etc/httpd/conf/httpd.conf and copy directory tag

<Directory “/var/www/site1”>
AllowOverride None
Require all granted
</Directory>

Then the site1.conf file like this

<VirtualHost *:80>

 

DocumentRoot “/var/www/site1”
ServerName site1.example.com
ErrorLog “/var/log/httpd/site1-error_log”
TransferLog “/var/log/httpd/site1-access_log”

 

</VirtualHost>

 

 

<Directory “/var/www/site1”>

 

AllowOverride None
Require all granted

 

</Directory>

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

firewall-cmd –list-services

Then Create index.html file inside /var/www/site1/index.html

nano  /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.

nano /etc/hosts

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

mkdir /var/www/site2

 

nano /var/www/site2/index.html

 

 

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

nano /etc/hosts

 

172.25.0.11 site2.example.com

Check for syntax errors

httpd -t

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

<Directory “/home/mydir”>

 

AllowOverride None

 

</Directory>

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

 

Leave A Comment