以下是配置 CentOS Apache2 服务器的步骤:
- 安装 Apache2:
- 更新系统:
sudo yum update -y。 - 安装 Apache:
sudo yum install httpd -y。
- 更新系统:
- 启动和启用 Apache2 服务:
- 启动服务:
sudo systemctl start httpd。 - 设置开机自启:
sudo systemctl enable httpd。
- 启动服务:
- 配置防火墙规则:
- 允许 HTTP 和 HTTPS 流量:
sudo firewall-cmd --permanent --add-service=http,sudo firewall-cmd --permanent --add-service=https,sudo firewall-cmd --reload。
- 允许 HTTP 和 HTTPS 流量:
- 配置虚拟主机(可选):
- 创建配置文件:在
/etc/httpd/conf.d/目录下创建如mydomain.conf的文件。 - 添加配置内容,如
标签内设置ServerName、DocumentRoot等。 - 创建网站根目录并设置权限:
sudo mkdir -p /var/www/yourdomain.com,sudo chown -R apache:apache /var/www/yourdomain.com。 - 重启 Apache 使配置生效:
sudo systemctl reload httpd。
- 创建配置文件:在
- 启用 SSL(可选):
- 安装 Certbot:
sudo yum install certbot python2 - certbot - apache - y。 - 获取证书:
sudo certbot --apache -d yourdomain.com。
- 安装 Certbot:
以上步骤可根据实际需求调整,配置过程中可查看/var/log/httpd/目录下的日志文件排查问题。