WEB SERVER IN LINUX

Setup Name Based Virtual Hosting in Linux

www.example.com
www.aitcloud.com


Check and install web server packages

 
#yum groupinstall “Basic Web Server”
#yum install httpd –y
      

Entry in hosts file


#vi /etc/hosts
192.168.2.1     ait.example.com     ait
192.168.2.1     www.example.com     www
192.168.2.1     www.aitcloud.com    www

Create two web hosting directories


#mkdir -p /var/www/html/example.com
#mkdir -p /var/www/html/aitcloud.com
#chown apache:apache -R /var/www/html/example.com
#chown apache:apache -R /var/www/html/aitcloud.com

Create index page for each website

example.com website


                                    
#cd /var/www/html/example.com

#vi index.html

<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>EXAMPLE.COM WEBSITE</title> </head> <body> <h1>Welcome to Example.com</h1> </body> </html>

aitcloud.com website


#cd /var/www/html/aitcloud.com

#vi index.html

<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>AITCLOUD.COM WEBSITE</title> </head> <body> <h1>Welcome to aitcloud.com</h1> </body> </html>

Configure Virtual Host for each websites


#vi /etc/httpd/conf/httpd.conf

<VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/html/example.com </VirtualHost> <VirtualHost *:80> ServerName aitcloud.com ServerAlias www.aitcloud.com DocumentRoot /var/www/html/aitcloud.com </VirtualHost>

Start/stop/restart Apache (httpd) Server


#systemctl start httpd
#systemctl stop httpd
#systemctl restart httpd
#systemctl status httpd
      

Open firewall for port number 80


#firewall-cmd --zone=public --add-service=http --permanent
#firewall-cmd –reload
      

Configure SELinux Security Framework to allow


#chcon -R -t httpd_sys_rw_content_t
/var/www/html/example.com
#chcon -R -t httpd_sys_rw_content_t
/var/www/html/aitcloud.com
      

Access the websites by hostname


Setup IP based Virtual Hosting in Linux


192.168.2.1     www.example.com
192.168.2.2     www.aitcloud.com
      

Entry in hosts file


#vi /etc/hosts
192.168.2.1   ait.example.com     ait
192.168.2.1   www.example.com     www
192.168.2.2   www.aitcloud.com    www
      

All other settings are same as per Name Based Virtual Hosting, only make the changes as highlighted for IP Based Virtual Hosting


#vi /etc/httpd/conf/httpd.conf

<VirtualHost 192.168.2.1:80>

ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/html/example.com </VirtualHost>

<VirtualHost 192.168.2.2:80>

ServerName aitcloud.com ServerAlias www.aitcloud.com DocumentRoot /var/www/html/aitcloud.com </VirtualHost>

Start/stop/restart Apache (httpd) Server


#systemctl start httpd
#systemctl stop httpd
#systemctl restart httpd
#systemctl status httpd
      

Access the websites by using IP Addresses