centos部署flask

首先安装uwsgi pip install uwsgi
新建uwsgiconfig.ini文件
配置uwsgiconfig.ini文件

[uwsgi]
# uwsgi 启动时所使用的地址与端口(可以与项目端口不一致)
socket = 127.0.0.1:5000
# 你的项目目录
chdir=/root/spider/byt
# python 启动程序文件
wsgi-file = flsk.py
# python 程序内用以启动的 application 变量名
callable = app
# 处理器数
processes = 4
# 线程数
threads = 2
# 缓冲区
buffer-size = 32768
#状态检测地址
stats = 127.0.0.1:9191

然后配置nginx
nginx在/etc/nginx路径
配置 nginx.conf


user  root;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx/nginx.pid;


events {
     
    worker_connections  1024;
}


http {
     
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout 1200;
    client_max_body_size 200m;

    gzip  on;

    include /etc/nginx/conf.d/*.conf;
    server {
     
         listen          80;
         server_name     zbt.zebra-c.com;
         location / {
     
                include uwsgi_params;
                uwsgi_pass 127.0.0.1:5000; #和你的uwsgi里的socket配置项保持一样
                uwsgi_param UWSGI_PYHOME /usr/bin/python2.7;#你的python路径
                uwsgi_param UWSGI_CHDIR /root/spider/bytedance;#你得文件路径
                uwsgi_param UWSGI_SCRIPT flsk:app;#你得启动名  比如你是在flsk文件里通过app启动
            }
        }
}

配置完nginx后,重启nginx nginx -s reload
然后启动uwsgi uwsgi --ini uwsgiconfig.ini
或者后台启动uwsgi uwsgi --ini uwsgiconfig.ini --daemonize myblog.out

你可能感兴趣的:(centos部署flask)