虚拟主机技术

1. 基于IP//对于最终用户来说,是透明的   SSL  https
2. 基于主机名(主机头)//对于最终用户来说,是透明的
3. 基于端口
ns
### Section 3: Virtual Hosts//虚拟主机

基于主机名
name-based,一个IP对应该多个主机名
一、DNS解析
www.tianyun.com,tianyun.com ===> 192.168.122.105
www.uplooking.com,uplooking.com ===> 192.168.122.105

二、虚拟主机

1. 准备工作
[root@node5 ~]# mkdir /var/www/{tianyun,uplooking}
[root@node5 ~]# echo "www.tianyun.com" > /var/www/tianyun/index.html
[root@node5 ~]# echo "www.uplooking.com" > /var/www/uplooking/index.html

2. 配置apache实现虚拟主机
注:基于虚拟主机的web服务,客户端是不能通过IP访问!
[root@node5 ~]# vim /etc/httpd/conf/httpd.conf

NameVirtualHost 192.168.122.105:80//支持基于名字的虚拟主机
<VirtualHost 192.168.122.105:80>
   DocumentRoot /var/www/tianyun
   ServerName www.tianyun.com
   ServerAlias tianyun.com
</VirtualHost>


<VirtualHost 192.168.122.105:80>
   DocumentRoot /var/www/uplooking
   ServerName www.uplooking.com
   ServerAlias uplooking.com
</VirtualHost>

======================================================================================
三、测试

仅支持使用名字访问

[root@node1~]# links --dump http://www.tianyun.com
  www.tianyun.com
[root@node1~]# links --dump http://tianyun.com
  www.tianyun.com

WEB服务器之apache 2_apache 虚拟主机


基于IP虚拟主机

客户端可以IP访问

规划:

网站      IP     主目录   log
www.tianyun.com     192.168.122.105    /var/www/tianyun
www.uplooking.com    192.168.122.103    /var/www/uplooking

===================================================================================

一、DNS解析

www.tianyun.com,tianyun.com ===> 192.168.122.105
www.uplooking.com,uplooking.com ===> 192.168.122.103

====================================================================================

二、虚拟主机

[root@node5 ~]# vim /etc/httpd/conf/httpd.conf

<VirtualHost 192.168.122.105:80>
   DocumentRoot /var/www/tianyun
   ServerName www.tianyun.com
   ServerAlias tianyun.com
</VirtualHost>

<VirtualHost 192.168.12.103:80>
   DocumentRoot /var/www/uplooking
   ServerName www.uplooking.com
   ServerAlias uplooking.com
</VirtualHost>

======================================================================================

三、测试

[root@station1 ~]# links --dump http://www.uplooking.com
  www.uplooking.com
[root@station1 ~]# links --dump http://uplooking.com
  www.uplooking.com

WEB服务器之apache 2_apache 虚拟主机_02