Bobcares

VirtualHost cannot occur within virtualhost section in WAMP

by | Jan 14, 2021

The error, VirtualHost cannot occur within virtualhost section in WAMP trigger while we try to add VirtualHost directive and reconfigure vhost.

As part of our Server Management Services, we assist our customers with several VirtualHost queries.

Today, let us find an effective solution for this error.

 

VirtualHost cannot occur within virtualhost section in WAMP

The causes of the error include:

  1. Another file includes the file vhost.conf, but from inside a virtualhost directive
  2. All VirtualHost directive not closed properly

VirtualHost cannot occur within virtualhost section in WAMP

 

Solution

  1. Keep only directives which we need and ensure that vhost.conf is not within VirtualHost directive.
  2. Strip vhost.conf from VirtualHost directive and other duplicated content.
  3. Ensure to properly close all VirtualHost directives and enter correct syntax.

Review NameVirtualHost

Generally, each interface and port on which Apache is set to listen to needs a NameVirtualHost directive. We can define the directive only once per port.

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
# SSL name based virtual hosts are not yet supported, therefore no
# NameVirtualHost statement here
Listen 443
</IfModule>

The default NameVirtualHost setting satisfies the requirements at present – Apache will apply named based virtual host logic and settings for HTTP requests made on any available interface (*) at port 80.

Define custom virtual hosts

Now you are ready to add your own virtual hosts so that you can start to serve your domains.

Create the vhost file for the domain:

<VirtualHost *:80>
ServerAdmin webmaster@domain1.com
ServerName domain1.com
ServerAlias www.domain1.com
DirectoryIndex index.html
DocumentRoot /wamp/www
LogLevel warn
</VirtualHost>

If someone enters the IP address of the server, they have the contents of that default vhosts file.

Apache searches the enabled vhost files in alphabetical order and if it can’t find one for the requested IP address or domain name, it serves the first one (alphabetically).

If we disable or delete the default vhost file, then the contents of domain1.com will display (being before domain2.com alphabetically).

This is something to consider when planning a website.

[Stuck with the error? We are available 24*7]

 

Conclusion

To conclude, VirtualHost cannot occur within virtualhost section in WAMP trigger while we try to add VirtualHost directive and reconfigure vhost. Today, we saw an effective method our Support Engineers employ.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.