尝试让 Pyramid 在 Apache 下运行mod_wsgi 但失败了

发布于 2024-10-21 13:05:53 字数 2152 浏览 5 评论 0原文

我已经安装了 mod_wsgi 并运行 Apache2。我已经确认 mod_wsgi 实际上可以按照 this 工作。

当我尝试运行 Pyramid 时,问题就出现了。我收到内部服务器错误,并且我的 Apache 错误日志包含异常:

AssertionError: The EvalException middleware is not usable in a multi-process environment

这是我的 VHost:

<VirtualHost *:80>
    ServerName  pyramidtest.dev
    DocumentRoot    /srv/pyramidtest.dev/www/
    AssignUserID    pyramidtest nogroup
    WSGIScriptAlias / /srv/pyramidtest.dev/pyramid/load.wsgi
</VirtualHost>

这是我的 load.wsgi

import site
site.addsitedir('/opt/pyramid/lib/python2.7/site-packages')

from pyramid.paster import get_app

application = get_app('/srv/pyramidtest.dev/pyramid/test/development.ini', 'main')

mod_wsgi 已编译为使用 /opt/python2.7作为 Python 解释器,但我在 /opt/pyramid 中的 virtualenv 下运行 Pyramid - 这就是为什么我在 load.wsgi 中有 site.addsitedir()

并且,如果需要的话,apache2 -V

Server version: Apache/2.2.9 (Debian)
Server built:   Dec 30 2010 11:50:24
Server's Module Magic Number: 20051115:15
Server loaded:  APR 1.2.12, APR-Util 1.2.12
Compiled using: APR 1.2.12, APR-Util 1.2.12
Architecture:   32-bit
Server MPM:     ITK
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/experimental/itk"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT=""
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/var/run/apache2/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf"

我缺少什么......?

I've got Apache2 running with mod_wsgi installed. I've confirmed that mod_wsgi actually works by following this.

The problem comes when I try to get Pyramid running. I get an Internal Server Error and my Apache error log contains the exception:

AssertionError: The EvalException middleware is not usable in a multi-process environment

Here's my VHost:

<VirtualHost *:80>
    ServerName  pyramidtest.dev
    DocumentRoot    /srv/pyramidtest.dev/www/
    AssignUserID    pyramidtest nogroup
    WSGIScriptAlias / /srv/pyramidtest.dev/pyramid/load.wsgi
</VirtualHost>

Here's my load.wsgi:

import site
site.addsitedir('/opt/pyramid/lib/python2.7/site-packages')

from pyramid.paster import get_app

application = get_app('/srv/pyramidtest.dev/pyramid/test/development.ini', 'main')

mod_wsgi is compiled to use /opt/python2.7 as the Python interpreter but I'm running Pyramid under a virtualenv in /opt/pyramid - This is why I have the site.addsitedir() in my load.wsgi.

And, in case it's needed, apache2 -V:

Server version: Apache/2.2.9 (Debian)
Server built:   Dec 30 2010 11:50:24
Server's Module Magic Number: 20051115:15
Server loaded:  APR 1.2.12, APR-Util 1.2.12
Compiled using: APR 1.2.12, APR-Util 1.2.12
Architecture:   32-bit
Server MPM:     ITK
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/experimental/itk"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT=""
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/var/run/apache2/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf"

What am I missing...?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏雪无痕 2024-10-28 13:05:53

您正在使用 EvalException 中间件(从错误消息中可以看出)。此错误的解决方案实际上包含在 调试技术 wiki 中mod_wsgi。

基本上,由于中间件允许对应用程序进行基于浏览器的交互式调试,因此所有请求都需要发送到同一进程;但是,您在嵌入模式下运行 mod_wsgi,默认情况下可以创建许多进程。

来自维基:

[...]如果你想使用这个
基于浏览器的交互式调试器,如果
以嵌入式方式运行您的应用程序
mod_wsgi 模式,您将需要
配置 Apache,使其仅
启动一个子进程来处理
请求并且它永远不会创建任何
额外的流程。阿帕奇人
所需的配置指令
实现这一点的方法如下。

启动服务器 1  
服务器限制 1

切换到守护进程模式(默认为单进程)也可以解决此问题,建议在嵌入式模式下运行。以下是 Apache 指令:

WSGIDaemonProcess pyramidtest.dev display-name=%{GROUP}
WSGIProcessGroup pyramidtest.dev

mod_wsgi 还可以为您添加 Python 路径。如果使用嵌入式模式,您可以使用:

WSGIPythonPath /opt/pyramid/lib/python2.7/site-packages

如果使用守护程序模式,请使用 WSGIDaemonProcess 指令的“python-path”选项。

WSGIDaemonProcess pyramidtest.dev display-name=%{GROUP} python-path=/opt/pyramid/lib/python2.7/site-packages
WSGIProcessGroup pyramidtest.dev

You're using the EvalException middleware (as can be seen from your error message). This solution to this error is actually covered in the Debugging Techniques wiki of mod_wsgi.

Basically, since the middleware allows browser-based interactive debugging of your application, all requests need to be sent to the same process; however, you are running mod_wsgi in embedded mode, which can create many processes by default.

From the wiki:

[...] if you want to be able to use this
browser based interactive debugger, if
running your application in embedded
mode of mod_wsgi, you will need to
configure Apache such that it only
starts up one child process to handle
requests and that it never creates any
additional processes. The Apache
configuration directives required to
achieve this are as follows.

StartServers 1  
ServerLimit 1

Switching to daemon mode (with a single process, the default) will also fix this problem, and is recommended over running in embedded mode. Here are the Apache directives:

WSGIDaemonProcess pyramidtest.dev display-name=%{GROUP}
WSGIProcessGroup pyramidtest.dev

mod_wsgi can also add the path to the Python path for you. If using embedded mode you can use:

WSGIPythonPath /opt/pyramid/lib/python2.7/site-packages

If using daemon mode, instead use the 'python-path' option to the WSGIDaemonProcess directive.

WSGIDaemonProcess pyramidtest.dev display-name=%{GROUP} python-path=/opt/pyramid/lib/python2.7/site-packages
WSGIProcessGroup pyramidtest.dev
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文