检查并设置文件/目录权限
apache或httpd)对网站目录有访问权限:sudo chown -R apache:apache /var/www/html # 修改所有者和组 sudo find /var/www/html -type f -exec chmod 644 {} \; # 文件权限644 sudo find /var/www/html -type d -exec chmod 755 {} \; # 目录权限755 调整SELinux策略(若启用)
sudo setenforce 0 /etc/selinux/config,不推荐直接禁用):sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?" sudo restorecon -Rv /var/www/html 修改Apache配置文件
httpd.conf中User和Group指令正确:User apache Group apache <Directory>指令是否允许访问目标目录,例如:<Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> 重启服务并验证
sudo systemctl restart httpd sudo systemctl status httpd # 确认服务运行状态 注意:修改配置前建议备份文件,权限设置需根据实际需求调整,避免过度开放权限。若问题仍存在,可通过tail -f /var/log/httpd/error_log查看详细错误日志。