一个IP建多个Web站点–主机头名法(apache篇)

首先,编辑httpd.conf文件,在尾部加上

NameVirtualHost *

编辑虚拟主机配置文件:

<VirtualHost *>
DocumentRoot "/htdoc" 
#html文件目录
ServerName  test.com 
#虚拟主机名
ServerAlias *.test.com
#做出响应的域名

##具体的目录配置

<Directory "/htdoc">
allow from all
</Directory>
DirectoryIndex index.php
</VirtualHost>

注意: ServerAlias 一栏,如果想让你的虚拟主机对应多个域名,可以将他们列出,并一一用空格隔开。

小窍门:
    如果你同时管理多个虚拟主机,而且经常变动,那就可以在httpd.conf文件的末尾加上一句
      
       include DIR/*.conf #DIR为你虚拟主机配置文件的目录

    然后,将每一个虚拟主机的配置做一个单独的.conf文件,放在DIR目录下,到时候只要添加删除文件就可以了。

anyShare分享到:
          

  1. No comments yet.
(will not be published)
*