centos部署flask

1.先安装uwsgi pip install uwsgi

2.在你的项目根目录下创建一个配置文件uwsgiconfig.ini(uwsgi支持多种配置文件格式,xml,ini,json等)

[uwsgi]socket = 127.0.0.1:8001 //启动程序时所使用的地址和端口,通常在本地运行flask项目,

//地址和端口是127.0.0.1:5000,
//不过在服务器上是通过uwsgi设置端口,通过uwsgi来启动项目,
//也就是说启动了uwsgi,也就启动了项目。
chdir = /home/www/ //项目目录

wsgi-file = manage.py //flask程序的启动文件,通常在本地是通过运行
// python manage.py runserver 来启动项目的

callable = app //程序内启用的application变量名

processes = 4 //处理器个数

threads = 2 //线程个数

stats = 127.0.0.1:9191 //获取uwsgi统计信息的服务地址

3.保存配置文件,我们可以通过键入 uwsgi uwsgiconfig.ini 来启动uwsgi

4.安装nginx

5.修改nginx配置好文件

events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

server {
listen 80; //默认的web访问端口
server_name xxx.xxx.xxx.xxx; //你的公网ip
#charset koi8-r;
access_log /home/www/WebBlogold/logs/access.log; //服务器接收的请求日志,
//需要在项目文件夹下创建
//logs文件夹,下同。
error_log /home/www/WebBlogold/logs/error.log; //错误日志

location / {

include uwsgi_params; //这里是导入的uwsgi配置

uwsgi_pass 127.0.0.1:8001; //需要和uwsgi的配置文件里socket项的地址
//相同,否则无法让uwsgi接收到请求。

uwsgi_param UWSGI_PYHOME /home/www/WebBlogold/venv; //python的位置(虚拟环境下)

uwsgi_param UWSGI_CHDIR /home/www/WebBlogold; //项目根目录

uwsgi_param UWSGI_SCRIPT manage:app; //启动项目的主程序(在本地上运行
//这个主程序可以在flask内置的
//服务器上访问你的项目)

}
}
}
下面是一堆#,全都是注释,不用管它。

6.启动nginx,uwsgi即可

 

posted @ 2018-01-07 12:54  无花1  阅读(1318)  评论(0编辑  收藏  举报