在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系统上成功搭建一个基本的网站。记得定期更新系统和软件,以确保网站的安全性和稳定性。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:如何在Ubuntu上部署网站