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

CentOS 7 Apache静态网站部署:home.html设为主页遇403问题求助

解决方案

1. 修复文件与目录权限

403 Forbidden最常见的原因是Apache进程没有读取文件或访问目录的权限,执行以下命令修正:

  • 递归设置目录与文件的所属用户组为Apache运行用户(CentOS 7中通常是apache):
    chown -R apache:apache /var/www/website
    
  • 递归设置目录权限为755(确保Apache能进入目录),文件权限为644(确保Apache能读取文件):
    find /var/www/website -type d -exec chmod 755 {} \;
    find /var/www/website -type f -exec chmod 644 {} \;
    

2. 调整Apache配置,解决Options冲突与DirectoryIndex生效问题

你的配置中VirtualHost块和<Directory>块的Options设置存在冲突,且DirectoryIndex的优先级需要明确,修改后的配置如下:

<VirtualHost *:80>
    ServerAlias cninfineon.com
    ServerAdmin root@localhost
    DocumentRoot /var/www/website
    DirectoryIndex home.html 
    ErrorLog /var/www/website/log/error.log
    CustomLog /var/www/website/log/access.log combined
    # 移除VirtualHost内的Options配置,统一在Directory块中设置
</VirtualHost>

<Directory "/var/www/website">
    # 禁用目录索引,保留符号链接支持
    Options -Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    # 重复定义DirectoryIndex,确保优先级
    DirectoryIndex home.html
</Directory>

Include conf.d/autoindex.conf

3. 验证配置并重启Apache

  • 检查配置文件语法是否正确:
    httpd -t
    
  • 若输出Syntax OK,则重启Apache服务:
    systemctl restart httpd
    

关键说明

  • Options -Indexes必须放在<Directory>块中,才能精准作用于网站根目录,避免和全局配置冲突。
  • DirectoryIndex在VirtualHost或<Directory>块中定义均可,若同时定义,<Directory>块的设置优先级更高。
  • 确保home.html确实存在于/var/www/website目录下,文件名大小写匹配(Linux系统区分大小写)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 17:51:28