Flask部署方案 #
一、Gunicorn #
1.1 安装 #
bash
pip install gunicorn
1.2 运行 #
bash
gunicorn -w 4 -b 0.0.0.0:5000 run:app
二、Nginx配置 #
nginx
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
三、Docker部署 #
Dockerfile:
dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "run:app"]
四、下一步 #
接下来让我们学习 博客系统,了解实战项目!
最后更新:2026-03-28