#!/bin/bash
# 配置参数
APP_NAME="my_flask_app"
APP_PORT=5000
NGINX_CONF="/etc/nginx/sites-available/$APP_NAME"
NGINX_CONF_ENABLED="/etc/nginx/sites-enabled/$APP_NAME"
APP_DIR="/var/www/$APP_NAME"
REPO_URL="https://github.com/yourusername/$APP_NAME.git"
# 安装依赖
sudo apt-get update
sudo apt-get install -y git python3 python3-pip nginx
# 克隆应用代码
git clone "$REPO_URL" "$APP_DIR"
cd "$APP_DIR"
# 安装Python依赖
pip3 install -r requirements.txt
# 配置Nginx
cat <<EOF > "$NGINX_CONF"
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:$APP_PORT;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
}
EOF
# 启用Nginx配置
sudo ln -s "$NGINX_CONF" "$NGINX_CONF_ENABLED"
sudo systemctl restart nginx
# 启动Flask应用
nohup python3 app.py > /dev/null 2>&1 &
echo "Deployment complete. Your app is running at http://yourdomain.com"