apache基于域名的虚拟主机配置

环境简介

Apache/2.4.10 (Win32) OpenSSL/0.9.8zb mod_fcgid/2.3.9

将多个域名解析到同一个IP上

因为我是本地模拟,没有多个真实的域名,只要将多个模拟的域名解析到本地。打开system32\drivers\etc\hosts文件,添加如下内容
这里写图片描述
这样当我访问,这三个域名的时候,就会自动映射到127.0.0.1ip上。

关于域名的查找顺序如下

1.从浏览器缓存中,查找对应域名的ip
在chrome地址栏输入地址:chrome://net-internals/#dn,可以查看谷歌浏览器的dns缓存
这里写图片描述

2.系统内的dns缓存
在命令提示符中输入ipconfig /displaydns,可以查看系统dns缓存
这里写图片描述
清空命令:ipconfig /flushdns
这里写图片描述
3.查询系统文件
4.查询路由器缓存
5.DNS服务器

apache配置

修改配置文件httpd.conf
去掉下面语句前的注释#,引入httpd-vhosts.conf文件

Include D:/Apache/conf/extra/httpd-vhosts.conf

修改httpd-vhosts.conf,添加如下内容

<VirtualHost *:80>
ServerName 127.0.0.1
DocumentRoot "D:/WWW/"
</VirtualHost>

<VirtualHost *:80>
    ServerName www.onethink.com
    DocumentRoot "D:/WWW/oneThink"
    DirectoryIndex main.html index.html index.htm index.php
    <Directory />
     AllowOverride All
     Order deny,allow
     allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName www.dedetest.com
    DocumentRoot "D:/WWW/dede_Test"
    DirectoryIndex main.html index.html index.htm index.php
    <Directory />
     AllowOverride All
     Order deny,allow
     allow from all
    </Directory>
</VirtualHost>

重启一下apache即可。
这里写图片描述

备注

Apache 在接受到请求时,首先会默认第一个VirtualHost,然后再找匹配的,如果没有匹配的,就是第一个VirtualHost起作用。

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值