在CentOS上部署Web应用通常涉及以下几个步骤:
-
更新系统:
sudo yum update -y
-
安装Web服务器:
- Apache:
sudo yum install httpd -y sudo systemctl start httpd sudo systemctl enable httpd
- Nginx:
sudo yum install nginx -y sudo systemctl start nginx sudo systemctl enable nginx
- Apache:
-
配置Web服务器:
-
Apache: 编辑
/etc/httpd/conf/httpd.conf
或创建新的配置文件在/etc/httpd/conf.d/
目录下。sudo vi /etc/httpd/conf.d/yourdomain.conf
配置示例:
ServerName yourdomain.com DocumentRoot /var/www/yourproject AllowOverride All Require all granted 重启Apache:
sudo systemctl restart httpd
-
Nginx: 编辑
/etc/nginx/conf.d/yourdomain.conf
。sudo vi /etc/nginx/conf.d/yourdomain.conf
配置示例:
server { listen 80; server_name yourdomain.com; root /var/www/yourproject; index index.php index.html; location / { try_files $uri $uri/ =404; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
重启Nginx:
sudo systemctl restart nginx
-
-
安装数据库(如果需要):
- MySQL:
sudo yum install mysql-server -y sudo systemctl start mysqld sudo systemctl enable mysqld sudo mysql_secure_installation
- MySQL:
-
部署Web应用:
- 将你的Web应用文件(如PHP项目、静态文件等)复制到
/var/www/yourproject
或你在配置文件中指定的目录。
- 将你的Web应用文件(如PHP项目、静态文件等)复制到
-
配置防火墙:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload
-
测试Web应用: 在浏览器中输入你的服务器IP地址或域名,查看是否能够正常访问你的Web应用。
以上步骤是一个基本的Web应用部署流程,具体的配置可能会根据你的应用需求和环境有所不同。