You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache2 AH00035权限拒绝错误:访问localhost日志报错求助

解决Apache AH00035路径权限缺失错误

当访问localhost时,Apache日志中频繁出现AH00035错误,提示路径组件缺少搜索权限。以下是详细信息:

错误日志

[Tue May 09 15:10:21.527729 2023] [core:error] [pid 26955] (13)Permission denied: [client ::1:34088] AH00035: access to / denied (filesystem path '/home/hazemhagrass/workspace') because search permissions are missing on a component of the path
[Tue May 09 15:10:21.539244 2023] [core:error] [pid 26957] (13)Permission denied: [client ::1:34096] AH00035: access to /robots.txt denied (filesystem path '/home/hazemhagrass/workspace') because search permissions are missing on a component of the path
[Tue May 09 15:10:21.620151 2023] [core:error] [pid 26955] (13)Permission denied: [client ::1:34088] AH00035: access to /favicon.ico denied (filesystem path '/home/hazemhagrass/workspace') because search permissions are missing on a component of the path, referer: http://localhost/

浏览器错误页面

浏览器访问localhost时的权限错误页面

虚拟主机配置文件

<VirtualHost *:80>

# Indexes + Directory Root.
DirectoryIndex index.php index.html
DocumentRoot /home/hazemhagrass/workspace/wordpress/demo

<Directory "/home/hazemhagrass/workspace/wordpress/demo">
      AllowOverride All
      Options FollowSymLinks
      Order allow,deny
      Allow from all
Require all granted

    </Directory>

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^index\.php$ - [L]
    RewriteCond $1 ^(index\.php)?$ [OR]
    RewriteCond $1 \.(gif|jpg|png|ico|css|js)$ [NC,OR]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ - [S=1]
    RewriteRule . /index.php [L]
</IfModule>
# END wordpress
    
    LogLevel warn
    CustomLog /var/log/apache2/demo-access.log combined
    ErrorLog /var/log/apache2/demo-error.log

问题原因

错误日志明确指向/home/hazemhagrass/workspace目录缺少搜索权限。Linux系统中,要访问某个目录下的文件,Apache运行用户(通常是www-data)必须拥有该路径上所有父目录的执行(搜索)权限,否则无法遍历到目标文档根目录。

解决步骤

  1. 修复父目录的搜索权限
    给路径上的所有父目录添加其他用户的执行权限:

    chmod o+x /home
    chmod o+x /home/hazemhagrass
    chmod o+x /home/hazemhagrass/workspace
    

    或者更稳妥地让Apache用户拥有目标目录的权限:

    chown -R www-data:www-data /home/hazemhagrass/workspace/wordpress/demo
    chmod -R 755 /home/hazemhagrass/workspace/wordpress/demo
    chmod o+x /home/hazemhagrass/workspace
    
  2. 验证权限设置
    执行以下命令检查各目录权限,确保每个目录的权限包含x(执行/搜索)位(比如drwxr-xr-x):

    ls -ld /home /home/hazemhagrass /home/hazemhagrass/workspace /home/hazemhagrass/workspace/wordpress/demo
    
  3. 重启Apache服务
    权限修改后必须重启Apache才能生效:

    sudo systemctl restart apache2
    

额外检查

  • 如果是RHEL/CentOS等启用SELinux的系统,可能需要调整文件上下文:
    sudo restorecon -R /home/hazemhagrass/workspace/wordpress/demo
    
  • 执行apache2ctl -S确认虚拟主机配置已正确加载。

内容的提问来源于stack exchange,提问作者Hazem Hagrass

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 10:47:49