3、 构建基于域名的虚拟主机
前提条件
[root@localhost bin]# cat /etc/resolv.conf
nameserver 192.168.0.20
search example.com
[root@localhost bin]# host www.crazylinux.com
www.crazylinux.com has address 192.168.0.10
[root@localhost bin]# host www.google.com
www.google.com has address 192.168.0.10
nameserver 192.168.0.20
search example.com
[root@localhost bin]# host www.crazylinux.com
www.crazylinux.com has address 192.168.0.10
[root@localhost bin]# host www.google.com
www.google.com has address 192.168.0.10
开始配置基于域名的虚拟主机
[root@localhost bin]# vim /usr/local/apache2/conf/httpd.conf 把388行前面的#号去掉
387 # Virtual hosts
388 Include conf/extra/httpd-vhosts.conf
[root@localhost bin]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 修改下面这样
NameVirtualHost 192.168.0.10
<VirtualHost 192.168.0.10>
DocumentRoot "/usr/local/apache2/htdocs/crazylinux"
ServerName www.crazylinux.com
ErrorLog "logs/www.crazylinux.com.error.log"
CustomLog "logs/www.crazylinux.com.access.log" common
</VirtualHost>
<VirtualHost 192.168.0.10>
DocumentRoot "/usr/local/apache2/htdocs/google"
ServerName www.google.com
ErrorLog "logs/www.google.com.error.log"
CustomLog "logs/www.google.com.access.log" common
</VirtualHost>
[root@localhost bin]# cd /usr/local/apache2/htdocs/
[root@localhost bin]# cd /usr/local/apache2/htdocs/
[root@localhost htdocs]# mkdir crazylinux
[root@localhost htdocs]# mkdir google
[root@localhost htdocs]# echo www.crazylinux.com >> crazylinux/index.html
[root@localhost htdocs]# echo www.google.com >> google/index.html
[root@localhost htdocs]# service apache restart
387 # Virtual hosts
388 Include conf/extra/httpd-vhosts.conf
[root@localhost bin]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 修改下面这样
NameVirtualHost 192.168.0.10
<VirtualHost 192.168.0.10>
DocumentRoot "/usr/local/apache2/htdocs/crazylinux"
ServerName www.crazylinux.com
ErrorLog "logs/www.crazylinux.com.error.log"
CustomLog "logs/www.crazylinux.com.access.log" common
</VirtualHost>
<VirtualHost 192.168.0.10>
DocumentRoot "/usr/local/apache2/htdocs/google"
ServerName www.google.com
ErrorLog "logs/www.google.com.error.log"
CustomLog "logs/www.google.com.access.log" common
</VirtualHost>
[root@localhost bin]# cd /usr/local/apache2/htdocs/
[root@localhost bin]# cd /usr/local/apache2/htdocs/
[root@localhost htdocs]# mkdir crazylinux
[root@localhost htdocs]# mkdir google
[root@localhost htdocs]# echo www.crazylinux.com >> crazylinux/index.html
[root@localhost htdocs]# echo www.google.com >> google/index.html
[root@localhost htdocs]# service apache restart
测试:在clinet中指定DNS服务器的ip