博客部署到生产环境
本文以 Ubuntu 22.04 为例。
安装依赖
sudo apt update
sudo apt install python3-venv nginx
配置 Gunicorn
pip install gunicorn
gunicorn -w 4 -b 127.0.0.1:8000 "app:create_app()"
Nginx 反向代理
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /uploads {
alias /path/to/AndrewBlog/uploads;
}
}
使用 systemd 管理进程
创建 /etc/systemd/system/andrewblog.service,确保服务开机自启并自动重启。
HTTPS(推荐)
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com
此文章为草稿,待完善后发布。