uWSGI Emperor 模式在 Virtualenv 之外不工作

uWSGI Emperor Mode Not Working Outside of Virtualenv

我正在尝试 运行 通过使用 Emperor 模式和容器通过 uWSGI 的 Django 应用程序,容器正确指向 ini 文件并且 ini 文件将 home 定义为 /home/ user/.virtualenvs/myvirtualenv,但这不起作用(日志显示连接已过早关闭)。但是如果我在 virtualenv 中 运行 相同的命令,它会完美地工作,所以我的猜测是 uWSGI 忽略了 home 选项。但是,这没有用,因为我需要 运行 几个不同的应用程序,每个应用程序都使用自己的 virtualenv(因此我需要皇帝模式)。

这是提到的容器 ini:

# mysite_uwsgi.ini file
[uwsgi]

#virtualenv            = /home/ariel/.virtualenvs/django-ag-panel/
# Django-related settings
# the base directory (full path)
chdir           = /home/ariel/Desarrollo/Django/django-ag-panel/ag_panel
# Django's wsgi file
module          = ag_panel.wsgi
# the virtualenv (full path)
home            = /home/ariel/.virtualenvs/django-ag-panel/

这是我用来 运行 the emperor 的命令(我使用与托管应用程序的用户相同的用户以避免更多文件权限问题):

uwsgi --emperor /etc/uwsgi.d/vassals

而我的封臣实际上就在那里:

[ariel@e11 ~]$ ls -l /etc/uwsgi.d/vassals/
total 0
lrwxrwxrwx. 1 root root 73 feb  7 21:37 ag_panel_uwsgi.ini -> /home/ariel/Desarrollo/Django/django-ag-panel/ag_panel/ag_panel_uwsgi.ini

如我所说,如果我在 virtualenv 中 运行 uWSGI 命令,一切正常:

workon django-ag-panel
uwsgi --emperor /etc/uwsgi.d/vassals

我做错了什么?

我遇到了 "prematurely closed connection" 问题,因为我试图通过 NGINX 和 uWSGI 与应用程序通信。真正的问题是容器没有正确加载,通过 运行 手动(在 virtualenv 之外)我发现问题是 'site' module not found 错误,反过来,由于全局安装(使用 yum,顺便说一句),分销商提供的 uWSGI 包没有内置 python 支持,实例无法正确启动。这将我们带到以下......

我认为可能很多人已经尝试按照这些教程在 Linux 上配置 uWSGI + NGINX:

  1. http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
  2. https://www.digitalocean.com/community/tutorials/how-to-deploy-python-wsgi-applications-using-uwsgi-web-server-with-nginx
  3. https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-14-04

可能还有其他一些;他们没有指出的是,你从 pip 命令和从包分发者那里得到的 uWSGI 版本有些不同,正如这个 uwsgi quickstart guide 指出的那样,分发者可以在 "modular"时尚:

One thing you may want to take into account when testing this quickstart with distro-supplied packages, is that very probably your distribution has built uWSGI in modular way (every feature is a different plugin that must be loaded). To complete this quickstart, you have to prepend --plugin python,http to the first series of examples, and --plugin python when the HTTP router is removed…

而您使用 pip 获得的软件包开箱即用 python 支持(至少在我的情况下,在 Fedora Linux 23 上)。更重要的是,由于包管理器和 pip 是独立的,你可以同时安装分发器和 pip 版本,如果这已经有问题,想象一下你的 virtualenv 中包的第三个本地版本。我遵循的步骤如下:

  1. 删除您系统中安装的所有 uwsgi 版本(或者至少尝试从 pip 或发行商提供的包中清理您的执行路径)
  2. 仅安装您需要的软件包版本(或仅保留一个,以防您在上一步中未删除所有内容)。
  3. 如果您选择模块化、分销商提供的版本:

    确保您还安装了 uwsgi-plugin-python.x86_64uwsgi-plugin-python3.x86_64 软件包,以及这些软件包:uwsgi-router-http.x86_64uwsgi-plugin-common.x86_64 以及您可能需要的其他东西。然后,运行 你的 uwsgi 实例与 --plugin 选项启用 python 或 python3 支持,在你的任何其他选项之前。 'site' module not found 错误现在应该消失了。您也可以在 ini 文件中使用该选项(如 plugin = python3),以防您 运行 使用配置文件或 vassals。

  4. 如果您选择 pip 版本:只需像平常一样使用它。

在所有情况下,请确保您调用的是哪个版本,这样应该没问题。