在CentOS Minimal上搭建Web服务器,通常会选择安装Apache或Nginx。以下是使用Apache作为Web服务器的步骤:
首先,确保你的系统是最新的:
sudo yum update -y
使用yum包管理器安装Apache:
sudo yum install httpd -y
安装完成后,启动Apache服务并设置开机自启动:
sudo systemctl start httpd
sudo systemctl enable httpd
确保防火墙允许HTTP和HTTPS流量:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
打开浏览器,访问你的服务器IP地址或域名,应该能看到Apache的默认页面。
如果你需要配置多个网站,可以使用虚拟主机。以下是一个简单的虚拟主机配置示例:
sudo vi /etc/httpd/conf.d/example.com.conf
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot "/var/www/html/example.com"
ServerName example.com
ServerAlias www.example.com
ErrorLog "/var/log/httpd/example.com-error_log"
CustomLog "/var/log/httpd/example.com-access_log" common
</VirtualHost>
sudo mkdir -p /var/www/html/example.com
echo "Welcome to Example.com" | sudo tee /var/www/html/example.com/index.html
sudo systemctl restart httpd
如果你需要启用HTTPS,可以使用Let’s Encrypt免费获取SSL证书:
sudo yum install certbot python2-certbot-apache -y
sudo certbot --apache -d example.com -d www.example.com
按照提示完成证书的安装和配置。
以上步骤涵盖了在CentOS Minimal上安装和配置Apache Web服务器的基本过程。你可以根据需要进一步自定义和扩展配置。