Monday, December 17, 2007

一个IP多个域名:用Apache建立虚拟主机

以下在内网中测试通过……

修改apache的conf(/etc/httpd/conf/httpd.conf)

1.修改ServerName为域名,如果没有则为IP。
比如我机子的IP是172.18.33.144
则修改为:
ServerName 172.18.33.144

2.添加NameVirtualHost项
NameVirtualHost 172.18.33.144
如果只有一个IP,也可以把IP域置为"*"

3.添加VirtualHost
首先添加一个全局的VirtualHost(这个Host可以直接通过访问IP访问到)
NameVirtualHost 172.18.33.144
<VirtualHost 172.18.33.144>
        ServerAdmin iveney@mymail.com
        DocumentRoot "/var/www/html"
        ServerName 172.18.33.144
</VirtualHost>

接着添加多个VirtualHost
<VirtualHost 172.18.33.144>
        ServerAdmin iveney@mymail.com
        DocumentRoot /mnt/E/Page
        ServerName www.iveneyPage.com
</VirtualHost>

<VirtualHost 172.18.33.144 >
        ServerAdmin iveney@mymail.com
        DocumentRoot /mnt/E/Page/Distributed
        ServerName www.iveneyDistributed.com
</VirtualHost>


最后测试,在/etc/hosts中添加域名解析项
172.18.33.144 www.iveneyPage.com
172.18.33.144 www.iveneyDistributed.com


然后重启apache,输入以上两个网址,成功.

No comments: