一个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