Home >Backend Development >PHP Tutorial >Apache virtual host configuration (multiple domain names access multiple directories), apache virtual host_PHP tutorial
Original text: http://dason.blog.51cto.com/658897/505312
Apache virtual host configuration (multiple domain names accessing multiple directories)
In order to facilitate the management of virtual hosts, I decided to use a method, which is to modify the httpd-vhosts.conf file. The first step is to make the extension file httpd-vhosts.conf effective:<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: After adding a virtual host, the apache service must be restarted. 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. In this way, accessing the domain name on the real machine will be redirected to the corresponding virtual machine. It is successful when hosting the website.