Apache2 错误 --- .htaccess:此处不允许评论

wru*_*kie 2 http apache-2.4 php7 ubuntu-18.04

今晚我将我的 VPS 从 Ubuntu 16.04 LTS 升级到 Ubuntu 18.04 LTS。一切都按预期进行,对 php aisle 5.6 进行了一些清理,并在 php aisle 7.4 上进行了一些库存货架。在我更改所有配置和模组后,Apache 毫无怨言地重新启动了;我以为我可以走了。但我的 4 个网站中有 3 个无法加载;没有干净的 404 页面,只有这个错误配置消息。

Internal Server Error 
The server encountered an internal error or misconfiguration and was unable to complete your request.
Run Code Online (Sandbox Code Playgroud)

审查后/var/log/apache2/error.log,我发现了这一点:

[Wed May 06 03:55:16.190469 2020] [core:alert] [pid 5657] [client 10.10.10.10:56897] 
/var/www/abc/example.com/.htaccess: No comments are allowed here, referer: https://example.com/
Run Code Online (Sandbox Code Playgroud)

在尝试了几种不同的方法之后,似乎开始行的注释不是问题,而是结束文件正常行的注释。删除这些评论或将这些#main office评论移动到自己的行中将使所有内容恢复在线。该# Allow from this IP address行仍在我的 .htaccess 文件中,但不会给我带来任何悲伤。

<Files wp-login.php>
    order deny,allow
    Deny from all
#   
#   Allow from this IP address
    allow from 10.10.10.10      #main office
    allow from 10.10.11.10      #satellite office
</Files>
Run Code Online (Sandbox Code Playgroud)

这是“错误”还是“功能”?在 Google 中搜索“.htaccess:此处不允许发表评论”几乎没有任何结果。(当第四次点击是外语时,你就知道你有麻烦了)。显然,跳转到 Ubuntu 18.04 或相关的 apache 或 php 更新是“何时”,但为什么呢?为什么这个内联文档有问题?是什么赋予了?

Esa*_*nen 6

这是一个功能,来自 Apache 的配置语法

\n\n
\n

以井号字符“#”开头的行被视为注释,\n 并将被忽略。注释可能\xc2\xa0而不是\xc2\xa0 与配置指令包含在同一行。指令之前出现的空格将被忽略,因此为了清晰起见,您可以缩进指令。空白行也被忽略。

\n
\n\n

这最近没有改变:在Apache 1.3中也是一样。如果升级后出现这些错误,则可能.htaccess以前从未使用过这些文件。除非绝对必要,还建议避免使用。.htaccess

\n