Original text: http://dason.blog.51cto.com/658897/505312
Apache virtual host configuration (multiple domain names access multiple directories)
In order to facilitate the management of virtual hosts, I decided to use a method, that is Modify the httpd-vhosts.conf file.
The first step is to make the extension file httpd-vhosts.conf effective:
1. Open the apache/conf/httpd.conf file
2. Find # Include conf/extra/httpd-vhosts.conf
3. Remove the previous Comment symbol #
4. Open apache/conf/extra/httpd-vhosts.conf
5. Add the above multi-port or multi-domain name code (here, take multiple domain names as an example):
6. Open apache2/conf/extra/ httpd-vhost.conf
Add the following in it:
Example:
<VirtualHost 192.168.1.1:80> ServerAdmin dason@sina.com (你的邮箱) DocumentRoot /usr/local/apache2/htdocs/Joomla(此虚拟主机的根目录) ServerName www.abc.com(此处为域名) ErrorLog /usr/local/apache2/htdocs/abc/error_log (日志) TransferLog /usr/local/apache2/htdocs/abc/access_log (日志) </VirtualHost> <VirtualHost 192.168.1.1:80> ServerAdmin dason@sina.com (你的邮箱) DocumentRoot /usr/local/apache2/htdocs/bbs (此虚拟主机的根目录) ServerName www.bbs.com (此处为域名) ErrorLog /usr/local/apache2/htdocs/bbs/error_log (日志) TransferLog /usr/local/apache2/htdocs/bbs/access_log (日志) </VirtualHost>
This example adds a www.abc.com host and a www.bbs.com virtual host.
Note: The apache service must be restarted after adding a virtual host.
If it is a server, you can access the corresponding virtual host website by directly accessing the domain name.
If it is a test environment (mine is a test environment), you can modify the hosts file of the real machine so that the test domain name is associated with the server (virtual machine) IP address, so that when you access the domain name on the real machine, you will be redirected to the corresponding one. The virtual host website is successful.
The above introduces the Apache virtual host configuration (multiple domain names accessing multiple directories), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.