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

新Arch Linux系统中Apache 2.4无法读取~/public_html的403权限问题

排查Arch Linux下Apache访问~/public_html返回403错误的步骤

1. 确认Apache运行用户的目录遍历权限

  • 获取Apache运行用户:
    systemctl show httpd --property=User
    
    Arch Linux默认运行用户为http。
  • 检查从根目录到~/public_html的每一级目录权限:
    执行ls -ld /home /home/你的用户名 /home/你的用户名/public_html,确认所有上级目录权限至少为711,public_html及子目录为755、文件为644。若家目录权限为700,需调整为711或755——否则http用户无法进入家目录,下级权限再正确也无效。

2. 验证Apache文档根目录的配置

  • 打开Apache主配置文件(通常为/etc/httpd/conf/httpd.conf)或站点配置文件,确认:
    • DocumentRoot指向正确的~/public_html路径,示例:
      DocumentRoot "/home/xxx/public_html"
      
    • 对应<Directory>块使用Apache 2.4的权限语法:
      <Directory "/home/xxx/public_html">
          Options Indexes FollowSymLinks
          AllowOverride None  # 匹配你禁用.htaccess的设置
          Require all granted
      </Directory>
      
    注意:Apache 2.4已废弃Allow from all语法,旧配置会直接导致权限拒绝。

3. 检查文件与目录的所有者

  • 执行ls -l /home/xxx/public_html,确认文件/目录的所有者及组权限:
    若文件所有者为root,虽理论上http用户可读,但建议将所有者改为你自己的用户:
    sudo chown -R 你的用户名:你的用户名 /home/xxx/public_html
    

4. 临时调整上级目录权限验证兼容性

  • 按照提示将从根到public_html的所有上级目录改为755:
    sudo chmod 755 /home
    sudo chmod 755 /home/你的用户名
    chmod 755 /home/xxx/public_html
    
  • 重启Apache服务:
    sudo systemctl restart httpd
    
    若访问恢复正常,则说明711权限在当前环境下存在兼容性问题,需保持755权限。

5. 查看Apache错误日志定位具体原因

  • 实时查看错误日志:
    tail -f /var/log/httpd/error_log
    
    访问触发403错误的页面后,日志会输出具体拒绝原因(如权限不足、配置错误等),这是最直接的排查依据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.02 04:42:30