nginx+uwsgi+flask

说明:没用虚拟环境

  1. 安装nginx,并新建一个conf配置文件,启动nginx
# xxx.conf

server {
    listen       80;
    server_name  localhost;

    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:5000;
    }

}
  1. 安装uwsgi
pip3 install uwsgi
ln -s /usr/python3/bin/uwsgi  /usr/bin/uwsgi (ln -s 源文件 目标文件)
# uwsgi.ini

[uwsgi]
socket = 127.0.0.1:5000 # 跟flask主程序文件汇总保持一致
chdir = /home/ybcrm/ # flask主程序所在路径
wsgi-file = manager.py # flask主程序文件名
callable = app # flask实例名
vacuum = true
log-maxsize = 5000
disable-logging = true
daemonize = /etc/uwsgi/uwsgiServer.log # 指定日志文件;如果使用 supervisors 需要注释掉,否则,supervisors 不能自动拉起 uwsgi 程序
stats=/etc/uwsgi/uwsgi.status
pidfile=/etc/uwsgi/uwsgi.pid
uid=root
gid=root
master=true # 主线程
threads = 2 # 线程数
processes = 4 # 处理器数
py-autoreload=1 # 热加载
# virtualenv = /rasa/zndhjqr_nlp/venv # 虚拟环境路径
# pythonpath= /rasa/zndhjqr_nlp # 虚拟环境使用的项目路径
  1. flask程序
# manager.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run(host='127.0.0.1',port=5000)
posted @ 2020-03-17 18:01  哈喽哈喽111111  阅读(414)  评论(0编辑  收藏  举报