Flask基于Fastcgi协议的Caddy配置

Flask ♥️ Caddy

本示例配置文件用来通过Caddy的fastcgi指令提供对Flask的访问。

如何运行

  1. 安装如下必须项:

    pip3 install -r requirements.txt
    
  2. 运行迷你Flask服务器

    python3 app.py
    
  3. 通过localhost:9000访问Flask。

Caddyfile

localhost:9000
fastcgi / unix:hello-world.sock

app.py

import sys
import os
import logging

from flup.server.fcgi import WSGIServer
from flask import Flask
app = Flask(__name__)

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

def main(app):
    try:
        WSGIServer(app, bindAddress='./hello-world.sock', umask=0000).run()
    except (KeyboardInterrupt, SystemExit, SystemError):
        logging.info("Shutdown requested...exiting")
    except Exception:
        traceback.print_exc(file=sys.stdout)


if __name__ == '__main__':
    main(app)

requirements.txt

Flask==1.0.2
flup-py3==1.0.3