CentOS7安装HTTP服务器详细指南
准备工作
确保系统更新至最新状态:
sudo yum update -y
安装必要工具:
sudo yum install wget net-tools -y
安装Apache HTTP服务器
通过Yum包管理器安装Apache:
sudo yum install httpd -y
启动与管理服务
启动Apache服务:
sudo systemctl start httpd
设置开机自启动:
sudo systemctl enable httpd
验证服务状态:
sudo systemctl status httpd
防火墙配置
开放HTTP(80)和HTTPS(443)端口:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
测试验证
创建测试页面:
echo "CentOS7 HTTP Server Running" | sudo tee /var/www/html/index.html
通过浏览器访问服务器IP地址,或使用命令:
curl http://localhost
预期显示"CentOS7 HTTP Server Running"
管理命令速查
- 重启服务:
sudo systemctl restart httpd
- 检查配置:
sudo apachectl configtest
- 查看错误日志:
sudo tail -f /var/log/httpd/error_log
常见问题处理
端口冲突检测:
sudo netstat -tulpn | grep ':80'
SELinux权限设置:
sudo setsebool -P httpd_can_network_connect 1