Apache:"Virtualhost not allowed here" 使用 If 条件时出错
Apache: "Virtualhost not allowed here" error when using If condition
我在 httpd.conf
内部有一个条件,看起来像这样:
<If "-f '/some/path/to/existing/file'">
<VirtualHost _default:$port1>
ServerName example.com
...config1...
</VirtualHost>
</If>
</Else>
<VirtualHost _default:$port1>
ServerName example.com
...config2...
</VirtualHost
</Else>
但是,它给我一个语法错误 AH00526,显示 "VirtualHost not allowed here"。如果我注释掉 "If Else" 条件,并将 VirtualHost 放在块外,它就可以工作。
如何在保持这种情况的同时解决这个问题?
您可以尝试以下方法。而不是使用 If
指令(实际上用于检查请求参数,您可以尝试使用 IfFile 指令。
IfFile
检查启动时文件是否存在。它没有其他选项,因此您需要确保您的文件检查对每个服务器都是独占的。
我在 httpd.conf
内部有一个条件,看起来像这样:
<If "-f '/some/path/to/existing/file'">
<VirtualHost _default:$port1>
ServerName example.com
...config1...
</VirtualHost>
</If>
</Else>
<VirtualHost _default:$port1>
ServerName example.com
...config2...
</VirtualHost
</Else>
但是,它给我一个语法错误 AH00526,显示 "VirtualHost not allowed here"。如果我注释掉 "If Else" 条件,并将 VirtualHost 放在块外,它就可以工作。
如何在保持这种情况的同时解决这个问题?
您可以尝试以下方法。而不是使用 If
指令(实际上用于检查请求参数,您可以尝试使用 IfFile 指令。
IfFile
检查启动时文件是否存在。它没有其他选项,因此您需要确保您的文件检查对每个服务器都是独占的。