flask 本地https调试


本地证书生成

使用mkcert工具

mkcert-v1.4.1-windows-amd64.exe example.com 127.0.0.1 localhost --cert-file  cert-file文件名   --key-file  key-file文件名

运行

  • 如果是用python调用app.py的main方法启动的话,只需要在main函数中写入

    ssl_context='adhoc' #直接调用 ssl_context=("server/server.pem","server/server.key.pem"))#调用本地证书文件

例如:
if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5000, debug=False, ssl_context='adhoc')
  • 如果是用pycharm运行(即调用flask run),只需要option中加入相应参数

例如:
-h 192.168.1.2  --cert adhoc
-h 192.168.1.2  --cert server/example.com.pem --key server/example.com-key.pem