Configure multiple sites in apache and sites in apache
The following configuration is available in the httpd. conf file (Note: remove the comments from the httpd. conf file)
Listen 80ServerName localhost<Directory /> AllowOverride none Require all denied</Directory>DocumentRoot "E:"<Directory "E:/Workshop/Apache"> Options Indexes FollowSymLinks AllowOverride None Require all granted</Directory>
(It is best to clear the browser cache before testing). Enter http: // localhost/Workshop/Apache/in the browser to access all files under E:/Workshop/Apache, note that the root Directory here is E:, but the above Directory is set with permissions, so it cannot access all the content under the E disk. If you change the above Directoy:
<Directory /> Options Indexes FollowSymLinks AllowOverride None Require all granted</Directory>
Then you can access everything on the e-disk from the browser. When you enter localhost in the browser, the browser will display all the content in the root directory of the e-disk, and you can access it. For security purposes, we usually do not do this, so we often set the method as follows:
Listen 80ServerName localhost<Directory /> AllowOverride none Require all denied</Directory>DocumentRoot "E:/Workshop/Apache"<Directory "E:/Workshop/Apache"> Options Indexes FollowSymLinks AllowOverride None Require all granted</Directory>
You can only access a specific directory through a browser, which is all the content in the E:/Workshop/Apache directory. Of course, for the second Dir, you can set access permissions for different folders in E:/Workshop/Apache.
Finally, you can set the VM settings in the following format (just at the end of the httpd. conf file ):
As shown in the following figure, you must first set the listening port, then specify the host address and port for NameVirtualHost, and then set the VirtualHost, including the SeverName, that is, the host name, and the document root directory, note: During local development, set ServerName to localhost or 127.0.0.1. The document root directory is the same as the directory settings, alternatively, you can set different access permissions for different folders in the document root directory. The X number indicates the VM that listens to all access ports.
Listen 81NameVirtualHost *:81<VirtualHost *:81> ServerName 127.0.0.1 DocumentRoot "C:/Users/Administrator/php/webroot1" <Directory "C:/Users/Administrator/php/webroot1"> Options Indexes FollowSymLinks AllowOverride None Require all granted</Directory></VirtualHost>Listen 82NameVirtualHost ×:82<VirtualHost *:82> ServerName 127.0.0.1 DocumentRoot "C:/Users/Administrator/php/webroot2" <Directory "C:/Users/Administrator/php/webroot2"> Options Indexes FollowSymLinks AllowOverride None Require all granted</Directory></VirtualHost>