Ubuntu 20.04+/CentOS 7+
Python 3.8+
SQLite3
Nginx
Supervisor/Gunicorn
sudo apt update
sudo apt install python3-pip python3-venv nginx
git clone https://your-repository-url.git
cd TodoList
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
export FLASK_APP=app.py
export FLASK_ENV=production
export SECRET_KEY=your-secret-key
from app import app
if __name__ == "__main__" :
app .run ()
gunicorn --bind 0.0.0.0:5000 wsgi:app --workers 4
1. 创建配置文件(/etc/nginx/sites-available/todolist)
server {
listen 80 ;
server_name your-domain.com;
location / {
proxy_pass http ://127.0.0.1:5000 ;
proxy_set_header Host $host ;
proxy_set_header X-Real-IP $remote_addr ;
}
location /static {
alias /path/to/TodoList/static;
}
}
sudo ln -s /etc/nginx/sites-available/todolist /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
1. 创建服务文件(/etc/systemd/system/todolist.service)
[Unit]
Description =TodoList WSGI Service
After =network.target
[Service]
User =www-data
Group =www-data
WorkingDirectory =/path/to/TodoList
Environment =" PATH=/path/to/TodoList/venv/bin"
ExecStart =/path/to/TodoList/venv/bin/gunicorn --workers 3 --bind unix:todolist.sock -m 007 wsgi:app
[Install]
WantedBy =multi-user.target
sudo systemctl start todolist
sudo systemctl enable todolist
配置防火墙:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
启用HTTPS(使用Certbot):
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx
定期备份数据库:
cp tasks.db tasks-$( date +%Y%m%d) .db
监控日志:
journalctl -u todolist.service -f
export FLASK_ENV=development
flask run --host=0.0.0.0 --port=5000