您的位置:首页 > 运维架构 > Nginx

[py]使用flaskup结合nginx实现文件上传

2017-09-25 17:10 981 查看
自己实现上传模块的话由于要考虑内存溢出问题,

听说了一个nginx upload模块,就查阅了下

往py上靠,使用flask自带服务器老跑—最后结合nginx来搞

老套路,先上图,看看这玩意能干嘛





部署很简单

写flaskup配置

mkdir /root/code/

cat >> /root/code/flaskup_config.py <<EOF
# -*- coding: utf-8 -*-

from passlib.hash import bcrypt

DEBUG = True
SECRET_KEY = '_\x12\xab\x90D\xc4\xfd{\xd9\xe2\xf3-\xa8\xd3\x1d\x1ej\x8b\x13x\x8ce\xc5\xe0'
FLASKUP_UPLOAD_FOLDER = '/srv/flaskup/data'
FLASKUP_MAX_DAYS = 10
FLASKUP_KEY_LENGTH = 4
MAIL_DEFAULT_SENDER = 'flaskup@example.com'
FLASKUP_ADMINS = ['admin@example.com', 'admin@example.org']
FLASKUP_NOTIFY = ['add', 'delete']
# FLASKUP_UPLOAD_PASSWORDS = [
#   ('$2a$12$oIWeziyq4wjF08gntfU4w.AQZfYbbQoK7y13ParN83G7ta.qtN2.e', 'pw1'),
#   ('$2a$12$zQ/hzog/iYr49fbo0mitS.y9f.uHP.7IyqWgk5/S1Ict50HRl4XxW', 'pw2'),
# ]
# FLASKUP_UPLOAD_PASSWORDS_CHECK = bcrypt.verify
EOF


写flask app

cat >>/root/code/app.py<<EOF
from flaskup import app
app.run()
EOF


使用nignx配置

FLASKUP_NGINX_UPLOAD_MODULE_ENABLED: must be set to True
FLASKUP_NGINX_UPLOAD_MODULE_STORE: must be set to the upload_store of the upload-module

FLASKUP_NGINX_UPLOAD_MODULE_ENABLED = True
FLASKUP_NGINX_UPLOAD_MODULE_STORE = /tmp/nginx_upload_module




参考:

https://github.com/lmeunier/flaskup
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: