flask+gunicron+nginx

我用的ubantu16.04

1.先安装:

pip3 install flask

pip3 install gunicorn

apt-get install nginx

2.做gunicron配置文件,在flask的项目根目录创建配置文件,文件名gunicron.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gevent.monkey

gevent.monkey.patch_all()

import multiprocessing
import os

if not os.path.exists('log'):
    os.mkdir('log')

debug = True
loglevel = 'debug'
bind = '127.0.0.1:8000'
pidfile = 'log/gunicorn.pid'
logfile = 'log/debug.log'
errorlog = 'log/error.log'
accesslog = 'log/access.log'

# 启动的进程数
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gunicorn.workers.ggevent.GeventWorker'

x_forwarded_for_header = 'X-FORWARDED-FOR'

3.启动gunicron

gunicorn  manger:app -D

4.在/etc/nginx/conf.d目录下配置nginx文件

自己创建一个conf文件,直接贴配置

#gzip  on;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    server {
        listen       80;
        server_name  idfa.theloan.xyz;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
           # root   html;
           # index  index.html index.htm;
            proxy_pass http://127.0.0.1:8000;
            access_log /home/nginx/api_access.log;
            proxy_read_timeout 60;
            error_log  /home/nginx/api_error.log;
        }}

5.重载nginx配置文件

sudo nginx -t
重启nginx服务
sudo service nginx restart

参考:https://www.jianshu.com/p/192e62a5cdd2

https://blog.csdn.net/xudailong_blog/article/details/80821326?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

原文地址:https://www.cnblogs.com/zy-mousai/p/13577462.html