以下是基于CentOS镜像配置Web服务器的步骤(以Apache和Nginx为例):
安装CentOS系统
sudo yum update -y
。安装Web服务器软件
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
sudo yum install epel-release -y # 安装EPEL仓库(若需最新版Nginx)
sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
/etc/httpd/conf.d/虚拟主机名.conf
,添加以下内容:<VirtualHost *:80>
ServerName example.com
DocumentRoot "/var/www/html/example.com"
ErrorLog "/var/log/httpd/example.com-error.log"
CustomLog "/var/log/httpd/example.com-access.log" combined
</VirtualHost>
sudo mkdir -p /var/www/html/example.com
sudo chown -R apache:apache /var/www/html/example.com
sudo chmod -R 755 /var/www/html
/etc/nginx/conf.d/虚拟主机名.conf
,添加以下内容:server {
listen 80;
server_name example.com;
root /var/www/html/example.com;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
sudo mkdir -p /var/www/html/example.com
sudo chown -R nginx:nginx /var/www/html/example.com
sudo chmod -R 755 /var/www/html
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo certbot --apache
以上步骤基于CentOS默认镜像,根据实际需求调整软件版本或配置参数即可。