gpt4 book ai didi

python - 试图让 Pyramid 在 Apache + mod_wsgi 下运行,但它失败了

转载 作者:太空宇宙 更新时间:2023-11-03 13:52:14 24 4
gpt4 key购买 nike

我已经在安装了 mod_wsgi 的情况下运行 Apache2。我已经通过关注 this 确认 mod_wsgi 确实有效.

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

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

这是我的虚拟主机:

<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"

我错过了什么......?

最佳答案

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

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

来自维基:

[...] 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

切换到守护进程模式(默认为单进程)也可以解决这个问题,建议不要在嵌入式模式下运行。以下是 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

关于python - 试图让 Pyramid 在 Apache + mod_wsgi 下运行,但它失败了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5269447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com