Ubuntu Python部署流程
一 环境准备与基础安装
二 部署Web应用的标准方式
三 反向代理与进程守护
/etc/systemd/system/gunicorn.service [Unit] Description=Gunicorn instance to serve yourapp After=network.target
[Service] User=your_username Group=www-data WorkingDirectory=/path/to/your/webapp Environment=“PATH=/path/to/your/webapp/venv/bin” ExecStart=/path/to/your/webapp/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/yourapp.sock app:app Restart=always
[Install] WantedBy=multi-user.target
启动与开机自启:sudo systemctl daemon-reload && sudo systemctl enable --now gunicorn && sudo systemctl status gunicorn
四 数据库与静态资源
五 安全与后续维护