In the httpd.conf file, there is the following configuration (note: omit the comment content of the httpd.conf file)
Listen 80 ServerName 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), then 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 has set permissions so it cannot access all the contents under the E drive. If the above Directory is changed to:
<Directory /> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
Then you can access everything in the E drive from the browser. When you enter localhost in the browser, the browser will display all the content in the root directory of the E drive and can access it. . For security reasons, we usually don’t do this, so the usual setting method is the following configuration:
Listen 80 ServerName 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>
Only allow access to a specific directory through the browser, which is all the content under the E:/Workshop/Apache directory. Of course, for the second Dir, you can set the access permissions for different folders under E:/Workshop/Apache.
Finally, let’s talk about the settings of the virtual host. Please set it in the following format (just put it at the end of the httpd.conf file):
As shown below, you need to set it first Listening port, then NameVirtualHost specifies the host address and port. The next step is to set up VirtualHost, including SeverName, which is the host name and document root directory. Note that for local development, set ServerName to localhost or 127.0.0.1. , the document root directory can be the same as the directory settings, or you can set different access permissions for different folders in the document root directory. The × sign represents the virtual host that listens to all access settings ports.
Listen 81 NameVirtualHost *: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 82 NameVirtualHost ×: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>