一个ip绑定多个域名

本文介绍了两种方式实现一个IP地址绑定多个域名,包括通过端口区分和使用ServerName。详细步骤包括配置虚拟主机目录、编辑httpd.conf与httpd-vhosts.conf文件、设置hosts文件以及进行测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、通过端口来区分不同的虚拟主机 (站点)

1)指定项目所在位置,例:d:/test1   d:/test2

2)php中配置conf下面的httpd.conf文件,启用extra目录下的httpd-vhosts.conf

 # Virtual hosts
   Include conf/extratpd-vhosts.conf 
3)配置我们的httpd-vhosts.conf,注销httpd.conf中的DocumentRoot
<VirtualHost 127.0.0.1:80>

     DocumentRoot "d:/test1"

     DirectoryIndex test.html index.html index.htm index.php  <-- test.html为自己想要的首页-->

<Directory/>

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>
</VirtualHost>

<VirtualHost 127.0.0.1:81>

     DocumentRoot "d:/test2"

     DirectoryIndex test.html index.html index.htm index.php  <-- test.html为自己想要的首页-->

<Directory/>

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>
</VirtualHost>


4)在c:/windows/system32/driver/etc/hosts文件中添加IP和域名的对应关系,例:

127.0.0.1:80 www.test1.com

127.0.0.1:81 www.test2.com

5)在httpd.conf文件中让apache监听81端口

Listen81

6)测试

www.test1.com   www.test2.com:81

二、通过ServerName端来区分不同的域名

1)指定项目所在位置,例:d:/test1   d:/test2

2)在httpd-vhosts.conf文件中添加配置

<VirtualHost *:80><--   Host改为*号-->

     DocumentRoot "d:/test1"

    ServerName  www.test1.com 

     DirectoryIndex test.html index.html index.htm index.php  <-- test.html为自己想要的首页-->

<Directory/>

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>
</VirtualHost>

<VirtualHost *:80><--   Host改为*号-->

     DocumentRoot "d:/test2"

    ServerName  www.test2.com 

     DirectoryIndex test.html index.html index.htm index.php  <-- test.html为自己想要的首页-->

<Directory/>

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>
</VirtualHost>

3)host中配置

127.0.0.1  www.test1.com

127.0.0.1  www.test2.com

4)测试

 www.test1.com

www.test2.com



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值