大网数据广告活动
服务器运维问答

Apache2 Error --- .htaccess: No comments are allowed here

· 52CE 我爱测

Tonight I upgraded my VPS from Ubuntu 16.04 LTS to Ubuntu 18.04 LTS. Everything worked as expected, had a little cleanup on php aisle 5.6 and some stocking shelves on php aisle 7.4. Apache restarted without a whimper after all my…

问题原文

原帖链接 · wruckie · CC BY-SA 4.0

Tonight I upgraded my VPS from Ubuntu 16.04 LTS to Ubuntu 18.04 LTS. Everything worked as expected, had a little cleanup on php aisle 5.6 and some stocking shelves on php aisle 7.4. Apache restarted without a whimper after all my config and mod changes; thought I was good to go. But 3 of my 4 sites would not load; no clean 404 page, just this misconfiguration message.

Internal Server Error 
The server encountered an internal error or misconfiguration and was unable to complete your request.

After reviewing the /var/log/apache2/error.log, I found this:

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

After trying several different things, it seems that comments that start the line are NOT the issue, it is comments that end a normal line of the file. Removing or moving these #main office comments to their own lines bring everything back online. The # Allow from this IP address line is still in my .htaccess file but does not cause me any grief.

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

Is this a 'bug' or a 'feature'? A search in Google for ".htaccess: No comments are allowed here" brings up almost nothing. (You know you are in trouble when the 4th hit is in a foreign language). Obviously the jump to Ubuntu 18.04 or the associated apache or php updates are the 'when', but WHY? Why is this in-line documentation problematic? What gives?

已采纳解答

原帖链接 · Esa Jokinen · CC BY-SA 4.0

This is a feature and comes from Apache's configuration syntax:

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. White space occurring before a directive is ignored, so you may indent directives for clarity. Blank lines are also ignored.

This hasn't changed recently: it's been the same in Apache 1.3. If these errors appeared after an upgrade, it's possible that these .htaccess files weren't even used before. It's also recommended to avoid using .htaccess unless absolutely necessary.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-05-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。