一个IP绑定多个域名的实现方法

方案一:

文字叙述:

具体步骤如下:比如讲apache服务器127.0.0.1 配置成 www.sohu.com
首先在http.conf文件中 做如下处理:
①关闭默认的 #DocumentRoot "C:/Apache2.2/htdocs“
②启用httpd-vhosts.conf文件 
# Virtual hosts 启用主机配置文件
Include conf/extra/httpd-vhosts.conf
2.在windows/system32/dirvers/etc/hosts文件中加入
127.0.0.1    www.hanshunping.com
3.在httpd-vhosts.conf文件中加入:
--简单配置方式
<VirtualHost 127.0.0.1:80>
    DocumentRoot "d:/myweb"
    DirectoryIndex my.html index.html index.htm index.php
    <Directory />
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>
--较为复杂的配置
<VirtualHost 127.0.0.1:80>
    ServerAdmin webmaster@dummy-host2.kk.com
    DocumentRoot "d:/temp"
    <Directory />
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
    Satisfy all
    </Directory>    
    ServerName www.hanshunping.com
    ErrorLog "logs/dummy-host2.kk.com-error.log"
    CustomLog "logs/dummy-host2.kk.com-access.log" common
</VirtualHost>
☞ 如何控制当在浏览器中输入 http://域名 比如 http://infoshare.cn 时 显示可供选择的文件,或者是直接访问默认的文件.
1. 默认直接访问某个欢迎页面 ,前面的步骤一样

<VirtualHost *:80>
    DocumentRoot "d:/infoshare" # 这个路径也可以再 htdos目录下
    ServerName  infoshare.cn
    DirectoryIndex index.php #默认就是d:/infoshare/index.php
    <Directory />
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>
2. 默认列表,而不是直接访问某个欢迎页面
2.1 如果虚拟目录就在 htdos这个目录下.
<VirtualHost *:80>
    DocumentRoot "d:/myenv/apache/htdos/infoshare"
    ServerName  infoshare.cn
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>
2.2 如果虚拟目录不在 htdos这个目录下.
<VirtualHost *:80>
    DocumentRoot "d:/infoshare"
    ServerName  infoshare.cn
<Directory />
    Options Indexes FollowSymLinks # 如果这里不加入 Indexes 就会提示403错误
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>





☞ 特别说明,如果有两个<VirtualHost 127.0.0.1:80> 则匹配第一个.

 

第一步:

第二步:

第三步:

 

第四步:注意

 

测试:

输入 http://www.yxh.com  显示第一个网站  这里是默认的80端口

输入 http://www.yxh.cn:81 显示第二个网站   这里要指定81端口

 

 

方案二:

与方案一的区别是

转载于:https://www.cnblogs.com/yxhblogs/p/4759138.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值