3

-------------------------------------

Run Multiple Websites on Single Server (Apache) - Name Based Virtual Host

Using Apache Name Based Virtual host we can run multiple websites on a single server.

Point your both domains to your server's public IP.

In order to configure name-based virtual hosting, you have to set the IP address on which you are going to receive the Apache requests for all the desired websites.  You can do this by NameVirutalHost directive within the Apache configuration file/etc/httpd/conf/httpd.conf file.

File excerpt: /etc/httpd/conf/httpd.conf

<VirtualHost 192.168.0.30:80>

ServerAdmin webmaster@serverkaka1.com

DocumentRoot /var/www/html/serverkaka1     

ServerName www.serverkaka1.com

</VirtualHost>

<VirtualHost 192.168.0.30:80>

ServerAdmin admin@serverkaka2.com

DocumentRoot /var/www/html/serverkaka2

ServerName www.serverkaka2.com

</VirtualHost>

Now, Restart Apache and Test.

# service httpd restart=====

                                   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx

Disable Directory Listing in Apache

If our website document directory does not have an index file, that time the Apache web server will show all the files and folder of the document root directory. Like as below image.

This feature could be turned off for a specific directory through 'options directive'available in the Apache configuration file.

Edit apache virtual host file.

# vim /etc/httpd/conf/httpd.conf                   ## for centos/redhat

# vim /etc/apache2/apache2.conf                  ## for ubuntu/debian

Add following line into virtual host file

<Directory /var/www/html>

    Options -Indexes

</Directory>

Restart Apache

# service httpd restart                                           ## for centos/redhat

# systemctl restart apache2                           ## for ubuntu/debian

Now apache shows /index of look like this:

---------------------