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

DirectAdmin下httpd.conf文档根路径自动追加SUB的问题及修复方法

Laravel子域名无法访问:DocumentRoot路径被自动追加SUB名称的问题及解决

问题背景

Laravel站点托管在Versio.nl,服务器维护后所有子域名均无法访问。检查发现httpd.conf中的DocumentRoot路径异常,末尾被自动追加了子域名(SUB)名称,导致路径不存在,触发配置警告。

当前DirectAdmin自定义httpd配置

|*if !SUB|
|?DOCROOT=/home/admin/domains/netwerkspel.nl/public_html/public|
|*endif|

|*if SUB="demo"|
|?DOCROOT=/home/admin/domains/netwerkspel.nl/public_html/demo/public|
|*endif|

|*if SUB="avn"| 
|?DOCROOT=/home/admin/domains/netwerkspel.nl/public_html/avn/public|
|*endif|

生成的异常httpd.conf片段

以ai.netwerkspel.nl为例,路径末尾被追加了ai:

<VirtualHost 185.xxx:80 >
    ServerName www.ai.netwerkspel.nl
    ServerAlias www.ai.netwerkspel.nl ai.netwerkspel.nl 
    ServerAdmin webmaster@netwerkspel.nl
    DocumentRoot /home/admin/domains/netwerkspel.nl/public_html/ai/public/ai   <<--------
    ScriptAlias /cgi-bin/ /home/admin/domains/netwerkspel.nl/public_html/ai/public/ai/cgi-bin/
    UseCanonicalName OFF
    <IfModule !mod_ruid2.c>
        SuexecUserGroup admin admin
    </IfModule>
    CustomLog /var/log/httpd/domains/netwerkspel.nl.ai.bytes bytes
    CustomLog /var/log/httpd/domains/netwerkspel.nl.ai.log combined
    ErrorLog /var/log/httpd/domains/netwerkspel.nl.ai.error.log
    <Directory /home/admin/domains/netwerkspel.nl/public_html/ai/public/ai>
        <FilesMatch "\.(inc|php|phtml|phps|php74)$">
            <If "-f %{REQUEST_FILENAME}">
                AddHandler "proxy:unix:/usr/local/php74/sockets/admin.sock|fcgi://localhost" .inc .php .phtml .php74
            </If>
        </FilesMatch>
    </Directory>
</VirtualHost>

配置检查警告

AH00112: Warning: DocumentRoot [/home/admin/domains/netwerkspel.nl/public_html/ai/public/ai] does not exist
AH00112: Warning: DocumentRoot [/home/admin/domains/netwerkspel.nl/public_html/ai/public/ai] does not exist
AH00112: Warning: DocumentRoot [/home/admin/domains/netwerkspel.nl/public_html/avn/public/avn] does not exist
AH00112: Warning: DocumentRoot [/home/admin/domains/netwerkspel.nl/public_html/avn/public/avn] does not exist

原因分析

服务器维护后,DirectAdmin的Apache配置模板被更新,默认规则发生变化:原自定义配置仅覆盖了DOCROOT变量,但新模板会自动将SUB名称追加到DOCROOT路径末尾,导致路径重复。

解决方法

方法一:自定义完整VirtualHost规则(推荐)

在DirectAdmin自定义httpd配置中,直接为每个子域名编写完整的VirtualHost片段,覆盖默认生成逻辑:

|*if SUB="ai"|
<VirtualHost |IP|:80>
    ServerName |DOMAIN|
    ServerAlias |DOMAIN| www.|DOMAIN|
    ServerAdmin webmaster@|DOMAIN|
    DocumentRoot /home/admin/domains/netwerkspel.nl/public_html/ai/public
    ScriptAlias /cgi-bin/ /home/admin/domains/netwerkspel.nl/public_html/ai/public/cgi-bin/
    UseCanonicalName OFF
    <IfModule !mod_ruid2.c>
        SuexecUserGroup admin admin
    </IfModule>
    CustomLog /var/log/httpd/domains/netwerkspel.nl.ai.bytes bytes
    CustomLog /var/log/httpd/domains/netwerkspel.nl.ai.log combined
    ErrorLog /var/log/httpd/domains/netwerkspel.nl.ai.error.log
    <Directory /home/admin/domains/netwerkspel.nl/public_html/ai/public>
        <FilesMatch "\.(inc|php|phtml|phps|php74)$">
            <If "-f %{REQUEST_FILENAME}">
                AddHandler "proxy:unix:/usr/local/php74/sockets/admin.sock|fcgi://localhost" .inc .php .phtml .php74
            </If>
        </FilesMatch>
    </Directory>
</VirtualHost>

<VirtualHost |IP|:443>
    SSLEngine on
    SSLCertificateFile /usr/local/directadmin/data/users/admin/domains/netwerkspel.nl.cert.combined
    SSLCertificateKeyFile /usr/local/directadmin/data/users/admin/domains/netwerkspel.nl.key
    ServerName |DOMAIN|
    ServerAlias |DOMAIN| www.|DOMAIN|
    ServerAdmin webmaster@|DOMAIN|
    DocumentRoot /home/admin/domains/netwerkspel.nl/public_html/ai/public
    ScriptAlias /cgi-bin/ /home/admin/domains/netwerkspel.nl/public_html/ai/public/cgi-bin/
    UseCanonicalName OFF
    <IfModule !mod_ruid2.c>
        SuexecUserGroup admin admin
    </IfModule>
    CustomLog /var/log/httpd/domains/netwerkspel.nl.ai.bytes bytes
    CustomLog /var/log/httpd/domains/netwerkspel.nl.ai.log combined
    ErrorLog /var/log/httpd/domains/netwerkspel.nl.ai.error.log
    <Directory /home/admin/domains/netwerkspel.nl/public_html/ai/public>
        <FilesMatch "\.(inc|php|phtml|phps|php74)$">
            <If "-f %{REQUEST_FILENAME}">
                AddHandler "proxy:unix:/usr/local/php74/sockets/admin.sock|fcgi://localhost" .inc .php .phtml .php74
            </If>
        </FilesMatch>
    </Directory>
</VirtualHost>
|*endif|

|*if SUB="avn"|
<VirtualHost |IP|:80>
    ServerName |DOMAIN|
    ServerAlias |DOMAIN| www.|DOMAIN|
    ServerAdmin webmaster@|DOMAIN|
    DocumentRoot /home/admin/domains/netwerkspel.nl/public_html/avn/public
    ScriptAlias /cgi-bin/ /home/admin/domains/netwerkspel.nl/public_html/avn/public/cgi-bin/
    UseCanonicalName OFF
    <IfModule !mod_ruid2.c>
        SuexecUserGroup admin admin
    </IfModule>
    CustomLog /var/log/httpd/domains/netwerkspel.nl.avn.bytes bytes
    CustomLog /var/log/httpd/domains/netwerkspel.nl.avn.log combined
    ErrorLog /var/log/httpd/domains/netwerkspel.nl.avn.error.log
    <Directory /home/admin/domains/netwerkspel.nl/public_html/avn/public>
        <FilesMatch "\.(inc|php|phtml|phps|php74)$">
            <If "-f %{REQUEST_FILENAME}">
                AddHandler "proxy:unix:/usr/local/php74/sockets/admin.sock|fcgi://localhost" .inc .php .phtml .php74
            </If>
        </FilesMatch>
    </Directory>
</VirtualHost>

<VirtualHost |IP|:443>
    SSLEngine on
    SSLCertificateFile /usr/local/directadmin/data/users/admin/domains/netwerkspel.nl.cert.combined
    SSLCertificateKeyFile /usr/local/directadmin/data/users/admin/domains/netwerkspel.nl.key
    ServerName |DOMAIN|
    ServerAlias |DOMAIN| www.|DOMAIN|
    ServerAdmin webmaster@|DOMAIN|
    DocumentRoot /home/admin/domains/netwerkspel.nl/public_html/avn/public
    ScriptAlias /cgi-bin/ /home/admin/domains/netwerkspel.nl/public_html/avn/public/cgi-bin/
    UseCanonicalName OFF
    <IfModule !mod_ruid2.c>
        SuexecUserGroup admin admin
    </IfModule>
    CustomLog /var/log/httpd/domains/netwerkspel.nl.avn.bytes bytes
    CustomLog /var/log/httpd/domains/netwerkspel.nl.avn.log combined
    ErrorLog /var/log/httpd/domains/netwerkspel.nl.avn.error.log
    <Directory /home/admin/domains/netwerkspel.nl/public_html/avn/public>
        <FilesMatch "\.(inc|php|phtml|phps|php74)$">
            <If "-f %{REQUEST_FILENAME}">
                AddHandler "proxy:unix:/usr/local/php74/sockets/admin.sock|fcgi://localhost" .inc .php .phtml .php74
            </If>
        </FilesMatch>
    </Directory>
</VirtualHost>
|*endif|

方法二:修改DirectAdmin Apache模板

  1. 登录服务器,找到模板文件(通常位于/usr/local/directadmin/data/templates/),比如virtual_host2.conf和virtual_host2_secure.conf
  2. 查找包含DocumentRoot |DOCROOT|/|SUB|的行,修改为DocumentRoot |DOCROOT|
  3. 重建Apache配置:
    /usr/local/directadmin/custombuild/build rewrite_confs
    

验证步骤

  1. 在DirectAdmin面板中重新生成httpd配置
  2. 重启Apache服务:service httpd restart
  3. 检查httpd.conf确认DocumentRoot路径正确
  4. 访问子域名验证服务恢复

内容的提问来源于stack exchange,提问作者M.Koops

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 18:55:33