As follows, we only configure a virtual host, assuming that the www.test.com corresponding IP is 192.168.1.1, by default, the user access matches the first virtual host, so that if the user in the Hosts file with 192.168.1.1 point to non-www.test . com, also can access to www.test.com, we should eliminate this situation, so in the front to add more than one virtual host, so that the virtual host to the non-existent files, so that when the user access, the default match is the first virtual host, only when access to Match to the correct virtual host when www.test.com
[[email protected] ~]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf # Pre-configuration <virtualhost *:80 > documentroot "/data/www" ServerName www.test.com <Directory/data/www> authname "please Input password " authtype basic authuserfile/data/.htpasswd Require valid-user </Directory> </VirtualHost>
[[email protected] ~]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf # after configuration <virtualhost * :80> documentroot "/tmp/123" ServerName 123.com</virtualhost><virtualhost *:80> DocumentRoot "/data/www" ServerName www.test.com <Directory/data/www> authname "please input Password " authtype basic authuserfile/data/.htpasswd Require valid-user </Directory> </VirtualHost>
Apache Configure default Virtual host