【问题标题】:<VirtualHost> causes our Apache server to produce "internal error"<VirtualHost> 导致我们的 Apache 服务器产生“内部错误”
【发布时间】:2023-03-25 05:08:01
【问题描述】:

当我将&lt;VirtualHost&gt; 指令添加到下面的.htaccess 文件时,我们的生产服务器news.XXX(我写XXX 而不是我们的真实域名)失败并出现内部错误。

请帮助了解错误原因。

Header set X-UA-Compatible "IE=edge"
AddType text/html .html
AddType text/x-component .htc
AddHandler server-parsed .html .xml
Options -Indexes +Includes +ExecCGI
Order allow,deny
Allow from all


#<FilesMatch "\.(xml|css|js)$">
#  ExpiresActive on
#  ExpiresDefault "access plus 15 minutes"
#</FilesMatch>

#<IfModule mod_expires.c>
#  ExpiresActive on
#  ExpiresDefault "access"
#  ExpiresDefault "access plus 15 minutes"
#  ExpiresByType text/html "access"
#  ExpiresByType text/plain "access"
#  ExpiresByType text/csv "access"
#  ExpiresByType application/xml "access"
#</IfModule>


RewriteEngine On

#DirectoryIndex /working-on-server.html
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ /working-on-server.html [L]

# Replaced real domain with XXX
<VirtualHost victor11.XXX>
DirectoryIndex /cgi-bin/news/index.NEW.fcgi
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /cgi-bin/news/index.NEW.fcgi [L,QSA]
</VirtualHost>

DirectoryIndex /cgi-bin/news/index.fcgi
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /cgi-bin/news/index.fcgi [L,QSA]

【问题讨论】:

    标签: apache .htaccess internal-server-error


    【解决方案1】:

    VirtualHost 指令不能在 .htaccess 文件中使用,因为 Apache 在包含 .htaccess 规则之前已经确定正在使用哪个 VirtualHost。

    如果您有多个使用同一个公共 html 文件夹的 VirtualHost,您可能想要这样做:

    <If "req('Host') == 'new.example.com'">
        DirectoryIndex /cgi-bin/news/index.NEW.fcgi
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /cgi-bin/news/index.NEW.fcgi [L,QSA]
    </If>
    <Else>
        DirectoryIndex /cgi-bin/news/index.fcgi
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /cgi-bin/news/index.fcgi [L,QSA]
    </Else>
    

    【讨论】:

      【解决方案2】:

      VirtualHost 指令仅在全局服务器范围/真实配置文件中有效。它在 htaccess 或任何其他配置部分中无效。

      如果你需要虚拟主机,你需要编辑Apache在启动时读取的配置文件。

      每个指令都在手册中列出了它有效的上下文。

      【讨论】:

        猜你喜欢
        • 2020-04-19
        • 2018-02-20
        • 2012-02-12
        • 1970-01-01
        • 2014-11-26
        • 1970-01-01
        • 1970-01-01
        • 2015-11-23
        • 2013-08-11
        相关资源
        最近更新 更多