<VirtualHost> 导致我们的 Apache 服务器生成 "internal error"

<VirtualHost> causes our Apache server to produce "internal error"

当我将 <VirtualHost> 指令添加到下面的 .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]

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

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

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

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

如果您有多个 VirtualHosts 使用同一个 public html 文件夹,您可能想做这样的事情:

<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>