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缓存
apache基于域名的虚拟主机配置_第1张图片

2.系统内的dns缓存
在命令提示符中输入ipconfig /displaydns,可以查看系统dns缓存
apache基于域名的虚拟主机配置_第2张图片
清空命令: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起作用。

你可能感兴趣的:(apache,域名,虚拟主机)