You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Win10环境下Apache2.4配置多站点访问域名显示htdocs目录列表问题咨询

Apache虚拟主机域名直接访问站点配置方案

出现该问题的核心原因是虚拟主机规则未完全生效,请求匹配到了默认的80端口虚拟主机,指向了htdocs根目录,按以下步骤修改配置即可解决:

1. 开启httpd.conf中的虚拟主机配置引入

打开Apache安装目录下的conf/httpd.conf文件,找到下方配置行,删除行首的#注释符:

# Include conf/extra/httpd-vhosts.conf

修改后为:

Include conf/extra/httpd-vhosts.conf

2. 完善httpd-vhosts.conf的权限配置

原虚拟主机配置缺少站点目录的访问权限规则,修改conf/extra/httpd-vhosts.conf内容如下:

<VirtualHost _default_:80>
    DocumentRoot "${SRVROOT}/htdocs"
    ServerName www.example.com:80
    <Directory "${SRVROOT}/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "${SRVROOT}/htdocs/Test.com"
    ServerName Test.com
    ServerAlias www.Test.com
    <Directory "${SRVROOT}/htdocs/Test.com">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
    DirectoryIndex index.html index.php
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "${SRVROOT}/htdocs/Test2.com"
    ServerName Test2.com
    ServerAlias www.Test2.com
    <Directory "${SRVROOT}/htdocs/Test2.com">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
    DirectoryIndex index.html index.php
</VirtualHost>

3. 确认默认首页配置

在conf/httpd.conf中找到DirectoryIndex配置项,确保配置中包含index.php:

DirectoryIndex index.html index.php

4. 验证配置并重启Apache

打开Apache的bin目录,在cmd中执行httpd -t验证配置语法是否正确,提示Syntax OK后重启Apache服务,清空浏览器缓存再访问Test.com、Test2.com即可直接加载对应站点内容。


内容的提问来源于stack exchange,提问作者qloq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 10:06:01