如何在 apache httpd.conf 中添加注释而不是完整的行?

How to add comment in apache httpd.conf not as a complete line?

在 apache conf 文件中,如果一行以 # 开头,则该行被视为注释。例如,

#This is a comment line
#And then the following is some real settings:
AllowOverride None

但是,这是不允许的。

#And then the following is some real settings:
AllowOverride None #A comment that starts in the middle of line

是否可以在行的中间开始评论?如果是,怎么做?

documentation表示不可能:

... Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on the same line as a configuration directive ...

Apache 逐行解释其配置文件。它将以 # 开头的行视为空行(或换行符)并跳过该行。 而且它没有表示注释的符号,因为 conf 文件有很多特殊符号,这可能会让它们禁用中间行注释。

我相信只有 # 被解析了,因为没有真正需要它。但是如果你真的需要你可以使用 IfDefine 块,除非匹配的变量有定义,否则它将被忽略。

<IfDefine myexisterenceIsForJustAComment>
...
</IfDefine>

查看讨论:https://bugzilla.redhat.com/show_bug.cgi?id=1349546

不确定最新版本 (< httpd-2.2.15-53) 是否支持这些,但您可以尝试以下在早期版本中受支持的内容。如果您使用的是旧版本,您可能会很幸运。

在 earlier/older 版本的 Apache 中,我记得可以在行尾包含注释(用双引号引起来),例如:

<Limit GET >
    Order Allow,Deny
    Allow from all
    Deny from xxx.xxx.xxx "# I am in inline comment"
</Limit>