Apache Name Based VirtualHost Example

ht‮w//:spt‬ww.lautturi.com
Apache Name Based VirtualHost Example

A Name Based VirtualHost in Apache is a way of hosting multiple websites on a single server, using a single IP address and port, and different hostnames to identify and serve the correct website to each client.

To create a Name Based VirtualHost in Apache, you can use the <VirtualHost> directive in the Apache HTTPD configuration file. The <VirtualHost> directive defines a new virtual host, and specifies the IP address and port that the virtual host will listen on.

Here is an example of using the <VirtualHost> directive to create a Name Based VirtualHost for a website named www.example.com:

<VirtualHost *:80>
    ServerName www.example.com
    DocumentRoot /var/www/example.com/public_html
</VirtualHost>

This directive will create a new virtual host that listens on the default HTTP port (80), and responds to requests for the hostname www.example.com. The DocumentRoot directive specifies the directory that contains the website's files and resources, which will be served to clients when they request the website.

To create multiple Name Based VirtualHosts on the same server, you can simply add multiple <VirtualHost> directives to the Apache HTTPD configuration file, each with a different ServerName and DocumentRoot setting. Apache will automatically serve the correct website to each client based on the hostname in the request.

Keep in mind that the exact syntax and options for the <VirtualHost> directive may vary depending on your specific Apache installation and configuration. It is always a good idea to refer to the official Apache documentation for detailed instructions and further information.

Created Time:2017-10-16 14:38:36  Author:lautturi