searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

linux操作系统自动化部署脚本

2025-03-13 19:22:16
1
0

#!/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"

0条评论
0 / 1000
王****际
180文章数
2粉丝数
王****际
180 文章 | 2 粉丝
原创

linux操作系统自动化部署脚本

2025-03-13 19:22:16
1
0

#!/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"

文章来自个人专栏
文章 | 订阅
0条评论
0 / 1000
请输入你的评论
0
0