centos

如何在CentOS上从零开始部署Web应用

小樊
54
2025-08-08 19:14:25
栏目: 智能运维

以下是在CentOS上从零开始部署Web应用的步骤:

  1. 更新系统

    sudo yum update -y  
    
  2. 安装Web服务器(以Nginx为例)

    sudo yum install nginx -y  
    sudo systemctl start nginx  
    sudo systemctl enable nginx  
    
  3. 配置防火墙

    sudo firewall-cmd --permanent --add-service=http  
    sudo firewall-cmd --permanent --add-service=https  
    sudo firewall-cmd --reload  
    
  4. 准备Web应用文件

    • 将项目文件(如静态文件、PHP代码等)上传至服务器指定目录(如/var/www/yourproject)。
    • 若需数据库支持,安装MySQL并完成初始化配置。
  5. 配置Web服务器

    • 编辑Nginx配置文件(如/etc/nginx/conf.d/yourproject.conf),指定根目录和域名:
      server {  
          listen 80;  
          server_name yourdomain.com;  
          root /var/www/yourproject;  
          index index.html index.php;  
          location / { try_files $uri $uri/ =404; }  
      }  
      
    • 重启Nginx使配置生效:
      sudo systemctl restart nginx  
      
  6. 部署应用并测试

    • 若为动态应用(如PHP),确保PHP-FPM服务已启动并配置正确。
    • 在浏览器中输入服务器IP或域名,验证应用是否正常访问。

可选步骤

参考来源:

0
看了该问题的人还看了