Name-Based Virtual Host in Apache

Multiple websites hosted on a single server are referred to as virtual hosting. Both “name-based” and “IP-based” configurations are possible, in which case every site has a unique IP address, and several sites share one IP. With this configuration, multiple websites can operate on the same server without the user being aware of it.

To set up name-based Virtual Hosts, follow these steps:

Step 1. Click on the “Config” button for the Apache server in your environment.

Step 2. Navigate to the /etc/httpd/conf/httpd.conf file.

Step 3. Before you start configuring your virtual host, ensure that the NameVirtualHosts line is uncommented:

Next, locate the block marked. To serve multiple hosts, you need to write a block for each host.

Write block

Every block must have a minimum of two directives inside it:

  • The ServerName directive gives a virtual host a unique identity. Enter your site’s primary hostname here, if possible.
  • DocumentRoot directive, which indicates the location of the host’s content in the filesystem.

5. You can utilize the ServerAlias directive, which is located inside the <VirtualHost> section if many servers wish to be reachable by multiple names. There, you can input every name that visitors to your website may use. The wildcard characters “*” and “?” are also available.

ServerAlias

6. Lastly, by adding additional directives inside the containers, you can adjust the virtual hosts’ configuration. The majority of directives can be inserted inside these containers, which will only alter the pertinent virtual host’s configuration.

Click the link to see if a specific directive is permitted. Only if they are not overridden by the virtual host settings will configuration directives defined in the main server context (apart from any containers) be used.

Save $100 in the next
5:00 minutes?

Register Here