【问题标题】:apache virtualhost (windows) not changing DocumentRootapache virtualhost(windows)不改变DocumentRoot
【发布时间】:2021-01-30 17:00:57
【问题描述】:

在 apache (windows 10) 上设置 vHost 时,一切正常 - 而不是 DocumentRoot。 它仍然是 htdocs 目录,而不是我在 httpd-vhosts.conf 中设置的目录:

Listen 80
<VirtualHost *:80>
    ServerAdmin your@email.com
    DocumentRoot "C:\Test"
    ServerName www.test.test
    <Directory "C:\Test">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

我还将域添加到 C:\Windows\System32\drivers\etc> 的 hosts 文件夹中。所以这部分工作正常:

# localhost name resolution is handled within DNS itself.
    127.0.0.1       localhost
#   ::1             localhost
    127.0.0.1       www.test.test

就在更改 httpd.conf 文件中的 documentRoot 时,如:

#DocumentRoot "${SRVROOT}/htdocs"
DocumentRoot "C:\Test"
<Directory "C:\Test">
...

它似乎工作。但这不是一个合适的解决方案...

【问题讨论】:

  • 我觉得不错。理论上路径应该使用正斜杠,但实际上反斜杠可以正常工作。你使用的是 Apache/2.4,实际加载 httpd-vhosts.conf 并在进行更改后重新启动服务?
  • @ÁlvaroGonzález “实际加载 httpf-vhosts.conf”是什么意思?之后我重新启动了一切。连电脑...

标签: apache virtualhost vhosts


【解决方案1】:

Apache 不会自动加载它在conf 目录下找到的每个文件。您需要使用Include 指令显式加载您需要的内容,如:

Include conf/extra/httpd-vhosts.conf

也可以加载完整的目录,例如:

Include "C:/Data/vhosts/*.conf"

您可以使用此命令验证正在加载哪些文件:

httpd -t -D DUMP_INCLUDES

...以及正在定义的虚拟主机:

httpd -t -D DUMP_VHOSTS

【讨论】:

  • 谢谢!我必须在什么文件中使用这些命令?在虚拟主机中?
  • 来自command prompt 或 PowerShell。
猜你喜欢
  • 2012-03-22
  • 2021-01-28
  • 2014-02-17
  • 2023-03-04
  • 2012-03-22
  • 2013-06-26
  • 2014-12-23
  • 2015-02-02
  • 1970-01-01
相关资源
最近更新 更多