zoukankan      html  css  js  c++  java
  • apache基于域名的虚拟主机配置(转)

    原文地址:

    http://blog.csdn.net/hsd2012/article/details/51537054

    环境简介

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

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

    因为我是本地模拟,没有多个真实的域名,只要将多个模拟的域名解析到本地。打开system32driversetchosts文件,添加如下内容 
    这里写图片描述 
    这样当我访问,这三个域名的时候,就会自动映射到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起作用。

  • 相关阅读:
    macOS Sierra 如何打开任何来源
    centos 安装git服务器,配置使用证书登录并你用hook实现代码自动部署
    Linux下修改Mysql的用户(root)的密码
    mysql主从复制
    CentOS7下安装MySQL5.7安装与配置
    gulp安装和使用
    libiconv库的安装和使用
    Android 开发中常见的注意点
    扯一扯 C#委托和事件?策略模式?接口回调?
    Python 学习开篇
  • 原文地址:https://www.cnblogs.com/afan/p/7340123.html
Copyright © 2011-2022 走看看