NGINX Unit + Flask = 在可用的应用程序模块中找不到

NGINX Unit + Flask = not found among the available application modules

这是在我上传时发生的 config.json:

sudo curl -X PUT --data-binary @config.json --unix-socket /var/run/control.unit.sock http://localhost/config
{
        "error": "Invalid configuration.",
        "detail": "The module to run \"python 3.6\" is not found among the available application modules."
}

我试过:PythonPython 3.7

我要上传的 config.json:

    {
  "listeners": {
    "*:1234": {
      "pass": "applications/flask"
    }
  },
  "applications": {
    "flask": {
      "type": "python 3.6",
      "processes": 5,
      "path": "/home/123/123/",
      "home": "/home/123/123/venv/",
      "module": "wsgi",
      "user": "root",
      "group": "root"
    }
  }
}

当我尝试使用 nginx 单元制作简单的 flask-demo 时,这一切都发生了

首先,您应该检查python模块是否安装正确。为了发现它们的位置,您可以使用 unitd --help 因为它显示了默认选项。

$ unitd --help
...

  --modules DIRECTORY  set modules directory name
                       default: "/usr/lib/unit/modules"

如果您使用自定义的 systemd 单元或脚本,您应该检查选项 --modules

简单列出modules目录下的文件:

$ ls /usr/lib/unit/modules
python3.6.unit.so  python3.7.unit.so

如果它们在那里,请检查 unit.log 的开头是否已正确加载:

$ sudo more /var/log/unit.log 
2020/04/29 22:24:47 [info] 13025#13025 discovery started
2020/04/29 22:24:47 [notice] 13025#13025 module: python 3.6.9 "/usr/lib/unit/modules/python3.6.unit.so"
2020/04/29 22:24:47 [notice] 13025#13025 module: python 3.7.5 "/usr/lib/unit/modules/python3.7.unit.so"
2020/04/29 22:24:47 [notice] 13024#13024 process 13025 exited with code 0
2020/04/29 22:24:47 [info] 13027#13027 router started
2020/04/29 22:24:47 [info] 13026#13026 controller started
2020/04/29 22:24:47 [info] 13027#13027 OpenSSL 1.1.1  11 Sep 2018, 1010100f

如果没有加载,日志会说明原因。 单元模块版本必须与安装的单元版本相匹配。如果您在系统中安装了新版本 运行 旧版本,您也应该重新安装单元模块 (apt install unit-dev unit-python3.6 unit-python3.7)。