快捷搜索:  

在Linux下设置WWW Server(3)

三、虚拟主机(Virtual Host)的设置

  作为系统管理员,若你只有一个IP地址,却有好几个域名,又要求访问每个域名都要看到不同的内容,那怎么办?总不至于为每个域名都配上一台服务器吧。这就要采用虚拟主机(Virtual Host)技术,幸好Apache就支持这种功能。虚拟主机有两种方式:IP-Based(基于IP式)、Name-based(基于域名式)。IP-Based指的是一个域名对应一个IP地址,而Name-based指的是多个域名对应一个IP地址。

  虚拟主机的设置并不复杂,只要在httpd.conf文件中加入相应的命令就行。

  下面是一个Name-based(基于域名式)虚拟主机的httpd.conf例子IP为:192.9.188.20,两个域名分别是long.com.cn、short.com.cn。

  httpd.conf:

  NameVirtualHost 192.9.188.20

  <VirtualHost WWW.long.com>

  ServerAdmin webmaster@long.com

  ServerName WWW.long.com

  DocumentRoot /home/httpd/long/html

  ErrorLog logs/error_log

  TransferLog logs/access_log

  </VirtualHost>

  <VirtualHost WWW.short.com>

  ServerAdmin webmaster@short.com

  ServerName WWW.short.com

  DocumentRoot /home/httpd/short/html

  ErrorLog logs/short.com-error_log

  TransferLog logs/short.com-access_log

  </VirtualHost>

  NameVirtualHost命令指定在哪个IP上设置虚拟主机。

  在VirtualHost命令中进行各个主机的具体设置。


顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论