在CentOS上部署Web应用通常涉及以下几个步骤:
准备环境:
httpd(Apache)、nginx、php、php-mysqlnd等。安装Web服务器:
yum安装Apache或Nginx。sudo yum install httpd
# 或者
sudo yum install nginx
配置Web服务器:
/etc/httpd/conf/httpd.conf文件,或者创建一个新的虚拟主机配置文件在/etc/httpd/conf.d/目录下。/etc/nginx/nginx.conf文件,或者创建一个新的服务器块配置文件在/etc/nginx/conf.d/或/etc/nginx/sites-available/目录下。安装PHP:
yum安装PHP及其相关模块。sudo yum install php php-mysqlnd php-gd php-xml php-mbstring
部署Web应用:
/var/www/html;对于Nginx,默认是/usr/share/nginx/html。数据库配置(如果应用需要):
sudo yum install mariadb-server mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
启动并启用Web服务器:
sudo systemctl start httpd
# 或者
sudo systemctl start nginx
sudo systemctl enable httpd
# 或者
sudo systemctl enable nginx
配置防火墙:
firewalld),确保开放HTTP(80)和HTTPS(443)端口。sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
测试部署:
SSL证书配置(可选但推荐):
监控和日志:
这些步骤提供了一个基本的指南,但具体的部署过程可能会根据你的Web应用的具体需求和配置有所不同。记得在部署过程中备份重要数据,并在生产环境中使用安全最佳实践。