我正在尝试在centos6.7虚拟机系统上设置Apache / 2.4.20,mod_wsgi / 4.5.2和Python / 2.7.11(由vagrant提供支持)。这三个软件 - httpd,mod_wsgi和Python都是从源代码编译而来的。
这是来自httpd,
的conf<Directory /srv/sources/myproject/apache>
<Files temp.wsgi>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject.com
WSGIProcessGroup myproject.com
WSGIScriptAlias / /srv/sources/myproject/apache/temp.wsgi
WSGISocketPrefix /var/run/wsgi
ServerName local.myproject
如果我使用以下测试代码作为我的temp.wsgi,
import os
import sys
import site
# Add site-packages of chosen virtualenv
site.addsitedir('/srv/VENVs/myproject/lib/python2.7/site-packages')
# Add the app's directory to PYTHONPATH
sys.path.append('/srv/sources/myproject')
sys.path.append('/srv/sources/myproject/app')
sys.path.append('/srv/sources/myproject/app/lib')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
# Activate virtual env
activate_env = os.path.expanduser("/srv/VENVs/myproject/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
def application(environ, start_response):
status = '200 OK'
output = sys.version
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
我可以在浏览器上获得以下输出,
2.7.11 (default, May 18 2016, 14:14:59)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]
现在,如果我将temp.wsgi更改为以下内容,
import os
import sys
import site
# Add site-packages of chosen virtualenv
site.addsitedir('/srv/VENVs/myproject/lib/python2.7/site-packages')
# Add the app's directory to PYTHONPATH
sys.path.append('/srv/sources/myproject')
sys.path.append('/srv/sources/myproject/app')
sys.path.append('/srv/sources/myproject/app/lib')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
# Activate virtual env
activate_env = os.path.expanduser("/srv/VENVs/myproject/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
import pip
def application(environ, start_response):
status = '200 OK'
output = sys.version
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return installed_packages_list
我的浏览器出现500错误。这出现在我的apache error_log(信息级别已启用)
上...
...
[Thu May 19 07:05:52.043868 2016] [wsgi:info] [pid 4400:tid 139938001123072] mod_wsgi (pid=4400): Create interpreter 'local.myproject.com|'.
[Thu May 19 07:05:52.045038 2016] [wsgi:info] [pid 4400:tid 139938001123072] [remote 192.168.33.1:3330] mod_wsgi (pid=4400, process='myproject.com', application='local.myproject.com|'): Loading WSGI script '/srv/sources/myproject/apache/temp.wsgi'.
[Thu May 19 07:05:52.299200 2016] [wsgi:error] [pid 4350:tid 139937921877760] [client 192.168.33.1:42475] Truncated or oversized response headers received from daemon process 'myproject.com': /srv/sources/myproject/apache/temp.wsgi
[Thu May 19 07:05:52.766389 2016] [core:notice] [pid 2346:tid 139938217453312] AH00052: child pid 4400 exit signal Segmentation fault (11)
[Thu May 19 07:05:52.766504 2016] [wsgi:info] [pid 2346:tid 139938217453312] mod_wsgi (pid=4400): Process 'myproject.com' has died, deregister and restart it.
[Thu May 19 07:05:52.766540 2016] [wsgi:info] [pid 2346:tid 139938217453312] mod_wsgi (pid=4400): Process 'myproject.com' terminated by signal 11
[Thu May 19 07:05:52.766640 2016] [wsgi:info] [pid 2346:tid 139938217453312] mod_wsgi (pid=4400): Process 'myproject.com' has been deregistered and will no longer be monitored.
[Thu May 19 07:05:52.767497 2016] [wsgi:info] [pid 4431:tid 139938217453312] mod_wsgi (pid=4431): Starting process 'myproject.com' with uid=501, gid=501 and threads=15.
...
...
有没有人对发生的事情有任何想法?最终目标是让django应用程序运行,我已经将问题缩小到这个 - 与配置有关。但到底是什么问题,我无法弄明白?
编辑(有人将此问题标记为重复):
如果有人遇到这个问题并且正在寻找答案,请注意在官方mod_wsgi邮件列表中询问了相同的问题, https://groups.google.com/d/msg/modwsgi/Nywtyy7r4Gw/hXyvEQHzCQAJ
答案简短:
在编译Python(和apache + mod_wsgi)源代码之前,我需要在我的centos框上安装expat-devel。这解决了问题中提出的问题。可悲的是,我不确定为什么它得到修复,所以我不愿意将其标记为解决方案。 (另请注意,mod_wsgi的开发人员一直在评论这个问题并直接在邮件列表上回复 - 非常有帮助的人,就我而言,是这个主题的权威)
与元相关的问题:
建议的“重复”确实提到了500错误,但这是由于apache-httpd的误配置(我认为)。这个问题有500错误,但是由于编译时配置问题,并且与'重复'没有任何关系。此外,2016年5月19日提出了这个问题,但2016年6月24日提出了“重复”问题。这可能是以后提出的问题的“重复”吗?我可以向大家保证,我没有时间旅行的能力!