How to Set a Default VirtualHost for each IP Address

April 1, 2024 / Virtual Server Web Hosting

This guide details the process of configuring non-existent sites and IP addresses to redirect to a specific site or default webpage, rather than serving content from the first VirtualHost entry associated with the IP address to which the domain resolves.

If a domain resolves to an IP address on a server but does not correspond to any existing site on the server, Apache defaults to serving content from the first site bound to that IP address.

Follow the steps:

  1. To modify this functionality, you must include a new VirtualHOST directive in
    /etc/apache2/conf.d/includes/pre_virtualhost_global.conf to ensure it takes precedence as the first VirtualHOST.
  2. It is important to be aware that creating a custom VirtualHost might lead to unforeseen consequences, and these adjustments should only be undertaken if you are proficient in troubleshooting VirtualHost problems in Apache.
  3. Please note that cPanel support does not offer direct assistance for Apache configuration customizations.

Follow the procedure:

  1. Log in to WHM.
  2. Select the “Service Configuration” option and click on the “Apache Configuration” sub-option.
    service configuration
  3. Select the “Include Editor” option.
    include
  4. Under “Pre Virtual Host Include”, select the “2.4.X” Apache version.
  5. Select the “All versions” option.
    All versions
  6. In the opened dialogue, insert the VirtualHost for the specified IP address across the web server ports.
  7. Proceed by selecting “Update”, and then subsequently select “Restart Apache”.
    Update

In this way, you can set a default VirtualHost for each IP address. Should you require assistance, contact our support staff. They are available 24×7.

Spread the love