如何将uWSGI站点配置为使用与构建uWSGI不同的Python解释器?(uWSGI+virtualenv+empero



我们的应用程序是为Python 2.7编写的。它有一个被配置为使用Python 2.7的virtualenv。系统安装的uWSGI是用Python 2.6构建的。这似乎是个问题。我们可以卸载/重新安装uWSGI以使用Python 2.7,但当我们最终拥有Python 3网站时会发生什么?这不是virtualenv的作用吗?我们可以在virtualenv中安装一个单独的uWSGI实例,但尚不清楚它是如何工作的——需要在启动时激活它,以及它如何与皇帝一起工作?我们应该使用uWSGI关键字"非特权二进制补丁"吗?

我们如何配置uWSGI,以便使用不同的Python解释器运行多个应用程序

我们在从uWSGI启动时看到了这个问题。

Python version: 2.6.9 (unknown, Oct 29 2013, 19:58:13)  [GCC 4.6.3 20120306 (Red
 Hat 4.6.3-2)]
Set PythonHome to /var/local/virtualenv/myapp
Python main interpreter initialized at 0xf86790
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 655200 bytes (639 KB) for 8 cores
*** Operational MODE: preforking ***
initialized 137 metrics
Traceback (most recent call last):
  File "/var/local/myapp/cgi/myapp.wsgi", line 6, in <module>
    from myapp import create_app
  File "./myapp/__init__.py", line 3, in <module>
    from app import create_app
  File "./myapp/app.py", line 1, in <module>
    import os
ImportError: No module named os
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 2500)
spawned uWSGI worker 1 (pid: 2521, cores: 1)
spawned uWSGI worker 2 (pid: 2522, cores: 1)
spawned uWSGI worker 3 (pid: 2523, cores: 1)
spawned uWSGI worker 4 (pid: 2524, cores: 1)
spawned uWSGI worker 5 (pid: 2525, cores: 1)
spawned uWSGI worker 6 (pid: 2526, cores: 1)
spawned uWSGI worker 7 (pid: 2527, cores: 1)
spawned uWSGI worker 8 (pid: 2528, cores: 1)
metrics collector thread started
*** Stats server enabled on 127.0.0.1:9191 fd: 27 ***
spawned uWSGI http 1 (pid: 2530)

该应用程序是用Flask编写的,并使用create_app模式来启动它。当使用virtualenv和Flask中内置的5000端口开发人员web服务器时,该应用程序运行良好。

ini文件如下所示:

[uwsgi]
chdir = /var/local/%n
callable = create_app
virtualenv=/var/local/virtualenv/%n
wsgi-file = /var/local/%n/cgi/%n.wsgi
master = true
daemonize = /var/log/uwsgi/%n.log
pidfile = /var/run/uwsgi/%n.pid
http = :9090

我们想以帝王模式运行网站。这是皇帝ini文件:

[uwsgi]
emperor = /etc/uwsgi/vassals
pidfile = /var/run/uwsgi/%n.pid
daemonize = /var/log/uwsgi/%n.log

最好的方法是为每个python版本都有一个uWSGI插件(就像发行版中的uWSGI包一样)

(旧址上的文档)http://projects.unbit.it/uwsgi/wiki/MultiPython

您可以在其他python/virtualenv版本中安装uwsgi。然后你可以在堆叠模式下使用uwsgi皇帝:

[uwsgi]
chdir = /var/local/%n
callable = create_app
virtualenv=/var/local/virtualenv/%n
wsgi-file = /var/local/%n/cgi/%n.wsgi
master = true
daemonize = /var/log/uwsgi/%n.log
pidfile = /var/run/uwsgi/%n.pid
http = :9090
unprivileged-binary-patch = /var/local/virtualenv/bin/uwsgi

最新更新