尝试让 Pyramid 在 Apache 下运行mod_wsgi 但失败了
我已经安装了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用 EvalException 中间件(从错误消息中可以看出)。此错误的解决方案实际上包含在 调试技术 wiki 中mod_wsgi。
基本上,由于中间件允许对应用程序进行基于浏览器的交互式调试,因此所有请求都需要发送到同一进程;但是,您在嵌入模式下运行 mod_wsgi,默认情况下可以创建许多进程。
来自维基:
切换到守护进程模式(默认为单进程)也可以解决此问题,建议在嵌入式模式下运行。以下是 Apache 指令:
mod_wsgi 还可以为您添加 Python 路径。如果使用嵌入式模式,您可以使用:
如果使用守护程序模式,请使用 WSGIDaemonProcess 指令的“python-path”选项。
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:
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:
mod_wsgi can also add the path to the Python path for you. If using embedded mode you can use:
If using daemon mode, instead use the 'python-path' option to the WSGIDaemonProcess directive.