要在 CentOS 上设置 Apache2 的默认文档,请按照以下步骤操作:
打开终端。
使用以下命令以 root 用户身份登录或使用 sudo
命令获取管理员权限:
sudo su
vi
编辑器作为示例:vi /etc/httpd/conf/httpd.conf
如果您更喜欢其他编辑器(如 nano
),请替换 vi
为您喜欢的编辑器。
DirectoryIndex index.html index.htm
这一行定义了默认文档的顺序。Apache 会按照从上到下的顺序查找这些文档,一旦找到就会停止搜索。
DirectoryIndex
行中文档的顺序。例如,如果您希望将 “index.php” 设置为默认文档,可以将其移动到第一位:DirectoryIndex index.php index.html index.htm
保存并关闭配置文件。
为了使更改生效,需要重启 Apache 服务器。在终端中输入以下命令:
systemctl restart httpd
现在,您已经成功设置了 CentOS Apache2 的默认文档。当用户访问网站时,Apache 会首先查找您指定的默认文档。