WampServer 在 httpd.conf 中配置多站点 (IP 配置法:不用每次修改 hosts 文件 + 域名配置法 )

因为要用 ThinkPHP 的当前最新版本 3.2.2,对应要求 PHP 的版本要高于 5.3.0,所以安装了 WampServer 2.2 ( Apache 2.2.21,PHP 5.3.10,MySQL 5.5.20) ,顺便记录一下在 httpd.conf 中配置多站点。

第一步:

安装 WampServer。我的安装路径是 D:wamp

第二步:

修改 D:wampinapacheApache2.2.21confextrahttpd-vhosts.conf

在文件的最后加上:

<VirtualHost *:80>
   
    DocumentRoot "D:/practise/php"
    ServerName www.dee.com
    <Directory "D:/practise/php">
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    </Directory>
</VirtualHost>

其中 D:/practise/php 是放置 PHP 项目的路径。

第三步:

在 httpd.conf 中找到如下代码:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

修改为:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
</Directory>

第四步:

配置多站点。在 httpd.conf 中找到:

ServerName localhost:80

<FilesMatch "^.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

把这两段中间的内容替换为:

DocumentRoot "d:/wamp/www/"

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

<Directory />"d:/wamp/www/"
    Options Indexes FollowSymLinks
    AllowOverride all
    Order Allow,Deny
    Allow from all
</Directory>

<VirtualHost 127.0.0.2>
    ServerName 127.0.0.2
    DocumentRoot "d:/mynewweb"
</VirtualHost>

<VirtualHost 127.0.0.3>
    ServerName 127.0.0.3
    DocumentRoot "d:/myqg"
</VirtualHost>

 注:如果不希望显示目录索引,就把 Options Indexes FollowSymLinks 中的 Indexes 去掉,则此时访问目录,目录为空或者不存在 index.php 或者 index.html 等文件时会显示 403 Forbidden。

设置默认的索引页的方式是在 httpd.conf 中加上

<IfModule dir_module>
    DirectoryIndex index.htm index.html index.php
</IfModule>

以上配置说明了目录中的默认索引页可以是 index.htm,index.html,index.php,可以通过调整它们之间的顺序来调整优先级。

每添加一个新的站点,按照上面最后两端的格式添加即可。

附:域名配置法

第 ① 步:

在 http.conf 中,把 Include conf/extra/httpd-vhosts.conf 前面的 "#" 去掉

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

第 ② 步:

在 httpd-vhosts.conf (D:wampinapacheApache2.2.21confextra)文件的最后,添加:

<VirtualHost *:80>
    ServerAdmin dee.com
    DocumentRoot "F:/www/newcrm"  
    ServerName   dee.com    
    ServerAlias  dee.com

    <directory "F:/www/newcrm">
        Options FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

注:F:/www/newcrm 为项目目录

第 ③ 步:

在 hosts 中添加:

127.0.0.1 dee.com

参考《教你wamp下多域名如何配置

原文地址:https://www.cnblogs.com/dee0912/p/4130397.html