以下是基于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默認鏡像,根據實際需求調整軟件版本或配置參數即可。