centos部署flask

1.先安装uwsgi pip install uwsgipython

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

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

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

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

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

processes = 4 //处理器个数app

threads = 2 //线程个数socket

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

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便可

相关文章
相关标签/搜索