gunicorn and pyinstaller and file-upload-app
#!/usr/bin/env python3
import shutil
from flask import Flask, Response, request
app = Flask(__name__)
@app.route('/<path:path>', methods=['GET', 'POST'])
def hello(path):
if request.method == "POST":
shutil.copyfileobj(request.stream, open(path, 'wb'), 4096)
return '', 201
else:
return Response(open(path, 'rb'), mimetype="application/octet-stream")
application = app
pyinstaller -y \
--hidden-import gunicorn.glogging \
--hidden-import gunicorn.workers.sync \
--hidden-import app \
file-server-app.py
upstream f {
server 127.0.0.4:3000;
keepalive 16;
}
server {
server_name f.*;
listen 443 ssl http2;
root /home/files;
location / {
proxy_buffering off;
proxy_request_buffering off;
if ($request_method = POST) {
proxy_pass http://f;
}
}
}
#!/usr/bin/env python3
from gunicorn.app.base import BaseApplication
class Application(BaseApplication):
def load_config(self):
s = self.cfg.set
s('bind', "0.0.0.0:8000")
s('workers', 3)
s('keepalive', 60)
s('timeout', 600)
s('accesslog', "-")
s('access_log_format', '%(t)s %(h)s "%(r)s" %(s)s %(b)s %(D)s "%(a)s"')
def load(self):
from app import application
return application
if __name__ == '__main__':
Application().run()