在CentOS from scratch上部署網站是一個涉及多個步驟的過程,以下是一個基本的指南,幫助你完成這個過程:
sudo yum update -y
sudo yum install httpd -y # 安裝Apache
sudo systemctl start httpd
sudo systemctl enable httpd
或sudo yum install nginx -y # 安裝Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
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 php-fpm -y
配置Apache:
編輯 /etc/httpd/conf/httpd.conf
或創建一個新的虛擬主機配置文件在 /etc/httpd/conf.d/
目錄下。
sudo nano /etc/httpd/conf.d/example.com.conf
添加以下內容:
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/var/www/html/example.com"
ServerAlias www.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/example.com
重啟Apache服務:
sudo systemctl restart httpd
配置Nginx:
編輯 /etc/nginx/nginx.conf
或創建一個新的服務器塊配置文件在 /etc/nginx/conf.d/
目錄下。
sudo nano /etc/nginx/conf.d/example.com.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;
}
}
重啟Nginx服務:
sudo systemctl restart nginx
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
/var/www/html/example.com
。sudo certbot --apache # 配置Apache
或sudo certbot --nginx # 配置Nginx
通過以上步驟,你應該能夠在CentOS系統上成功搭建一個基本的網站。記得定期更新系統和軟件,以確保網站的安全性和穩定性。