服务器 频道

虚拟主机的例子(上)

在多于一个IP的情况下使用基于域名的虚拟主机。

注意

  在这里讨论的任何技术都可以推广到使用任意数量的IP 地址。

  服务器有两个IP地址。一个(172.20.30.40)用于“主”服务器—— server.domain.com而另外一个 (172.20.30.50),我们将用于构建两个或多个虚拟主机。

服务器配置

  Listen 80
  
  # This is the "main" server running on 172.20.30.40
  ServerName server.domain.com
  DocumentRoot /www/mainserver
  
  # This is the other address
  NameVirtualHost 172.20.30.50
  
  <VirtualHost 172.20.30.50>
  
DocumentRoot /www/example1
  ServerName www.example1.com
  
  # Other directives here ...
  
  
</VirtualHost>
  
  <VirtualHost 172.20.30.50>
  
DocumentRoot /www/example2
  ServerName www.example2.org
  
  # Other directives here ...
  
  
</VirtualHost>

  任何不是针对172.20.30.50的请求都将由主服务器来伺服。 而提交给172.20.30.50却没有主机名或没有 Host:头的请求,都将为www.example1.com伺 服。

0
相关文章