Configuration methods and examples for binding virtual hosts using top level domain names under XAMPP

  • 2020-05-10 23:15:35
  • OfStack

Sometimes you need 1 some top-level domain access to access your local project, this time you need to configure the virtual host, to your directory binding 1 domain name, multi-domain binding access. (locally, you can modify the hosts file to bind any domain name you want, such as www.a.com or localdemo).

Now suppose you have two directories, one in /xampp/htdocs/a, and one in /xampp/htdocs/b.

Now you want to access the www.a.com directory /xampp/htdocs/a, and the www.b.com directory /xampp/htdocs/b when you test locally. You can bypass the configuration of Apache, because XAMPP is nothing more than the integration of Apache and other environment integration package, the implementation of multiple domain name is realized through the configuration of Apache.

The following configuration is for version 1.7.4 of XAMPP Windows, but it also applies to other versions of XAMPP.

Download address: / / www. ofstack. com softs / 308. html

1. First, modify the hosts file in C:/WINDOWS\system32\drivers\etc, open it with Notepad++ or notepad, and add:


127.0.0.1 www.a.com
127.0.0.1 www.b.com

2. Open the xampp\apache\conf\ httpd.conf file and search for "Include conf/extra/ httpd-vhosts.conf".

The httpd-vhosts.conf is enabled, and the default httpd.conf configuration is disabled (make sure the httpd-vhosts.conf file is also enabled for the virtual host configuration, see article 3). Access to this IP domain name will all point to the first virtual host in vhosts.conf. (note the first one, see the fourth one)

3, in the virtual host Settings file xampp\apache\conf\extra\ httpd-vhosts. conf:

Cancel ## before NameVirtualHost *:80, so vhosts.conf is enabled, and the default httpd.conf configuration is disabled by default. The virtual host configuration will only be set in httpd-vhosts.conf.


<VirtualHost *:80>
DocumentRoot /xampp/htdocs/a
ServerName www.a.com
</VirtualHost> <VirtualHost *:80>
DocumentRoot /xampp/htdocs/b
ServerName www.b.com
</VirtualHost>

4. After setting up article 3, you will find that access to localhost points directly to the a path set, which is discussed in article 2. That is, when vhosts is turned on, the default httpd configuration will be disabled, and the default access will point to the first setting in vhosts. At this point you need to configure the localhost directory back to Settings.

<VirtualHost *:80>
DocumentRoot /xampp/htdocs/
ServerName localhost
</VirtualHost>

At this point, the virtual host of XAMPP has been set up, and now access localhost is still the original XAMPP help guide. Access www.a.com will point to the a directory bound, and access www.b.com will point to the b directory bound.

Example reference:

XAMPP adds VirtualHost to support multiple sites

In the c:\xampp\apache\conf\extra\ httpd-vhosts.conf file, add the following:


NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "E:/php/wordpress"
ServerName wordpress
</VirtualHost> // The following 1 Segments must be added, otherwise they cannot be accessed <Directory "E:/php/wordpress">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>

But you can combine the top two in 1

<VirtualHost *:80>
DocumentRoot "E:/php/wordpress"
ServerName wordpress
<Directory "E:/php/wordpress">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

(this 1 section brings back the default access Settings of localhost and will have to be placed later)


<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/"
ServerName localhost </VirtualHost>


In C:\WINDOWS\ system \drivers\etc add the following to the hosts file:


127.0.0.1 wordpress


Related articles: