在CentOS上配置Web服务器通常涉及以下步骤:
安装Web服务器软件:
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
配置网络:
nmcli
命令配置网络接口,创建网络会话实例,配置远程控制服务。配置防火墙:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
设置虚拟主机:
/etc/httpd/conf.d/
目录下创建一个新的配置文件,例如example.com.conf
,并添加以下内容:VirtualHost *:80
ServerAdmin admin@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 combined
sudo mkdir -p /var/www/html/example.com
sudo chown -R apache:apache /var/www/html/example.com
sudo systemctl restart httpd
配置安全性:
sudo setenforce 1
sudo yum install certbot python2-certbot-apache -y
sudo certbot --apache
监控和维护:
性能优化:
sudo yum install mod_cache -y
LoadModule cache_module modules/mod_cache.so
以上步骤是在CentOS上配置Web服务器的基本流程。根据具体需求,可能还需要进一步配置和优化服务器。