简体   繁体   English

uWSGI Emperor模式无法在Virtualenv外部运行

[英]uWSGI Emperor Mode Not Working Outside of Virtualenv

I'm trying to run a Django application through uWSGI by using the Emperor Mode and vessels, the vessel points correctly to the ini file and the ini file defines home as /home/ user /.virtualenvs/myvirtualenv, however this doesn't work (the log says that the connection was prematurely closed). 我正在尝试通过使用Emperor模式和器皿通过uWSGI运行Django应用程序,器皿正确指向ini文件,并且ini文件将home定义为/ home / user /.virtualenvs/myvirtualenv,但是这不起作用(日志显示该连接过早关闭)。 But if I run the same command while in the virtualenv, it all works perfectly, so my guess is that uWSGI is ignoring the home option. 但是,如果我在virtualenv中运行相同的命令,那么它们都可以正常运行,因此我的猜测是uWSGI忽略了home选项。 This is, however, not useful since I need to run a couple different apps each using their own virtualenv (hence why I need emperor mode). 但是,这没有用,因为我需要使用各自的virtualenv运行几个不同的应用程序(因此,我需要使用Emperor模式)。

This is the mentioned vessel ini: 这是提到的船只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/

And this is the command I use to run the emperor (I'm using the same user as the one that hosts the app to avoid yet more file permission issues): 这是我用来运行皇帝的命令(我使用的是与托管该应用程序的用户相同的用户,以避免出现更多文件权限问题):

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

And my vassal is in fact there: 我的附庸国实际上在那里:

[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

As I said, everything works correctly if I run the uWSGI command while in the virtualenv: 就像我说的,如果我在virtualenv中运行uWSGI命令,那么一切都可以正常工作:

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

What am I doing wrong? 我究竟做错了什么?

I was getting the "prematurely closed connection" issue because I was trying to communicate to the app through NGINX and uWSGI. 我遇到“过早关闭的连接”问题,因为我试图通过NGINX和uWSGI与该应用进行通信。 The real issue was that the vessel was not being loaded correctly, and by running it manually (outside of the virtualenv) I found out that the issue was a 'site' module not found error, this was, in turn, caused because the globally installed (using yum, by the way), distributor-provided uWSGI package didn't have python support built in and the instance couldn't start correctly. 真正的问题是船只未正确加载,并且通过手动运行(在virtualenv之外),我发现问题是'site' module not found错误,这是由于全局安装(通过yum进行安装)时,发行商提供的uWSGI软件包没有内置python支持,因此实例无法正确启动。 Which takes us to the following… 这将我们带到以下...

I think that probably many people has tried to configure uWSGI + NGINX on Linux by following these tutorials: 我认为可能很多人通过遵循以下教程来尝试在Linux上配置uWSGI + NGINX:

  1. http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html 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 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 https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-14-04

And probably some other ones; 可能还有其他一些; what they don't point out is that the uWSGI version you get from the pip command and from the package distributor are somewhat different, as this uwsgi quickstart guide points out, the distributor may compile uWSGI in a "modular" fashion: 他们没有指出的是,您从pip命令和软件包分发程序获得的uWSGI版本有所不同,正如此uwsgi快速入门指南指出的那样,分发程序可以以“模块化”方式编译uWSGI:

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). 使用发行版软件包测试此快速入门时,您可能需要考虑的一件事是,您的发行版很可能已经以模块化方式构建了uWSGI(每个功能都是必须加载的不同插件)。 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… 要完成此快速入门,您必须在第一个示例系列的前面加上--plugin python,http,并在删除HTTP路由器后加上--plugin python ...

Whereas the package you get with pip comes with python support right out of the box (at least in my case, on Fedora Linux 23). pip附带的软件包直接提供了python支持(至少就我而言,在Fedora Linux 23上)。 What is more, since the package manager and pip are independent you can have both the distributor and the pip version simultaneously installed, and if this is already problematic, imagine now a third, local version of the package in your virtualenv. 而且,由于软件包管理器和pip是独立的,因此您可以同时安装分发服务器版本和pip版本,如果已经存在问题,请想象一下您的virtualenv中的软件包的第三个本地版本。 The steps I followed were as follows: 我遵循的步骤如下:

  1. Remove all and every version of uwsgi you have installed in your system (or at least try to clean up your execution path from either the pip or the distributor-provided package) 删除系统中已安装的所有uwsgi版本(或至少尝试从pip或发行商提供的软件包中清理执行路径)
  2. Install only the version of the package you need (or leave only one, in case you didn't remove everything in the previous step). 仅安装所需版本的软件包(或仅保留一个版本,以防您在上一步中未删除所有内容)。
  3. In case you choose the modular, distributor-provided version: 如果您选择发行商提供的模块化版本:

    Make sure you also install the uwsgi-plugin-python.x86_64 and uwsgi-plugin-python3.x86_64 packages, along with these ones: uwsgi-router-http.x86_64 , uwsgi-plugin-common.x86_64 , and something else you might need. 确保还安装了uwsgi-plugin-python.x86_64uwsgi-plugin-python.x86_64 uwsgi-plugin-python3.x86_64软件包,以及以下软件包: uwsgi-router-http.x86_64uwsgi-router-http.x86_64 uwsgi-plugin-common.x86_64以及其他可能需要的uwsgi-plugin-common.x86_64 Then, run your uwsgi instance with the --plugin option to enable either python or python3 support, before any of your other options. 然后,使用--plugin选项运行--plugin实例以启用python或python3支持,然后再使用其他任何选项。 The 'site' module not found error should be gone now. 'site' module not found错误现在应该消失了。 You can also use that option in the ini file (like plugin = python3 ) in case you run using config files or vassals. 如果您使用配置文件或vassals运行,也可以在ini文件中使用该选项(例如plugin = python3 )。

  4. In case you choose the pip version: Just use it like you would normally do. 如果您选择的是pip版本:请像平常一样使用它。

In all cases, make sure which version you are calling and you should be fine. 在所有情况下,请确保您正在呼叫哪个版本,并且应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM