WEB服务器之apache 2

虚拟主机技术

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


基于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


本文出自 “cisco” 博客,请务必保留此出处http://1585654.blog.51cto.com/1575654/1384025

WEB服务器之apache 2,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。