Flask的部署

当前对部署flask的一些学习:

1.全局安装nginx

1.1 nginx的配置文件怎么写?

$ sudo rm /etc/nginx/sites-enabled/default
$ sudo touch /etc/nginx/sites-available/flask_project
$ sudo ln -s /etc/nginx/sites-available/flask_project /etc/nginx/sites-enabled/flask_project

删除默认的配置然后创建一个新的配置文件“flask_project",软链接到enabled。
打开 flask_project:

$ sudo vim /etc/nginx/sites-enabled/flask_project

在文件中写入:

server {
    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location /static {
        alias  /home/www/flask_project/static/;
    }
}

1.2 nginx的启动和重启

$ sudo /etc/init.d/nginx start
$ sudo /etc/init.d/nginx restart

每次修改配置文件后记得重启nginx。

2.虚拟环境里安装gunicorn

pip install gunicorn

3.开启gunicorn:

$ cd /home/www/flask_project/
$ gunicorn app:app -b localhost:8000

https://realpython.com/blog/python/kickstarting-flask-on-ubuntu-setup-and-deployment/

 

--End--



posted @ 2015-08-10 09:02  ibg  阅读(445)  评论(0编辑  收藏  举报