How to configure multiple virtual domain names with Apache

After apache is installed, the virtual server is not enabled by default. If you want to configure a virtual server on the local apache, similar to the virtual host purchased online, you can configure it according to the following steps:

1. Modify the hosts file of this machine as follows

 Example:
127.0.0.1 localhost
127.0.0.1 xlb.com

127.0.0.1 xlb2.com

2. Open the Apache installation directory, find the httpd.conf file, and remove the # sign in front of the following two lines of text respectively.  
LoadModule vhost_alias_module modules/mod_vhost_alias.so
remove # means to enable apache's virtual host function.  
Include conf/extra/httpd-vhosts.conf  
remove the # in this line to import the virtual host configuration from the conf/extra/httpd-vhosts.conf file.

3. Open the httpd-vhosts.conf file in the extra directory and set the default configuration

<VirtualHost *:80>
    ServerAdmin 
[email protected]
    DocumentRoot "/www/docs/dummy-host.localhost"
    ServerName dummy-host.localhost
    ServerAlias http://www.dummy-host.localhost/
    ErrorLog "logs/dummy-host.localhost-error_log"
    CustomLog "logs/dummy-host.localhost-access_log common"
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/www/docs/dummy-host2.localhost"
    ServerName dummy-host2.localhost
    ErrorLog "logs/dummy-host2.localhost-error_log"
    CustomLog "logs/dummy-host2.localhost-access_log common"
</VirtualHost>

Change to the directory and domain name you want

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "D:/wamp/www/"
    ServerName localhost
    ServerAlias ​​localhost
    ErrorLog "logs/localhost-error_log"
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy -host.localhost
    DocumentRoot "D:/wamp/www/web/"
    ServerName test.com  (fill in the main domain name)
    ServerAlias ​​*.test.com  (The server alias here can support pan-resolution, that is, all subdomains can be resolved and bound to the virtual host)
    ErrorLog "logs/localhost-error_log"
</VirtualHost>

If there is a 403 error after finishing, find it in httpd.conf:
<Directory />
Options FollowSymLinks ExecCGI Indexes
AllowOverride None
Order deny, allow
Deny from all
Satisfy all
</Directory>

更改为
<Directory />
Options FollowSymLinks ExecCGI Indexes
AllowOverride None
# Order deny,allow
# Deny from all
# Satisfy all
</Directory>

After the above configuration, you can enter xlb.com in the browser to access the site under the directory you set

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325811582&siteId=291194637