问题
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...?
回答1:
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
来源:https://stackoverflow.com/questions/5269447/trying-to-get-pyramid-running-under-apache-mod-wsgi-but-its-failing