在CentOS上搭建Web服務器是一個相對簡單的過程,可以選擇使用Apache或Nginx作為Web服務器軟件。以下是使用Apache和Nginx搭建Web服務器的詳細步驟:
sudo yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
/var/www/html
,你可以在這里放置你的網站文件。sudo vi /var/www/html/index.html
添加一些簡單的HTML內容,然后保存并退出。
sudo yum update -y
sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo yum install mariadb-server mariadb -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
sudo yum install php php-mysql -y
sudo systemctl restart httpd
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/example.com
sudo vi /etc/httpd/conf.d/example.com.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 systemctl restart httpd
以上步驟展示了如何在CentOS上安裝和配置基本的Web服務器。根據具體需求,可能還需要進一步配置SSL證書、優化性能、設置監控等。