Flask基于Fastcgi协议的Caddy配置

Flask ♥️ Caddy

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

如何运行

  1. 安装如下必须项:

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

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

Caddyfile

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

app.py

  1. import sys
  2. import os
  3. import logging
  4. from flup.server.fcgi import WSGIServer
  5. from flask import Flask
  6. app = Flask(__name__)
  7. @app.route('/')
  8. def hello_world():
  9. return 'Hello, World!'
  10. def main(app):
  11. try:
  12. WSGIServer(app, bindAddress='./hello-world.sock', umask=0000).run()
  13. except (KeyboardInterrupt, SystemExit, SystemError):
  14. logging.info("Shutdown requested...exiting")
  15. except Exception:
  16. traceback.print_exc(file=sys.stdout)
  17. if __name__ == '__main__':
  18. main(app)

requirements.txt

  1. Flask==1.0.2
  2. flup-py3==1.0.3