我正在尝试使用apache部署mod_wsgi来运行django应用程序,但是我收到错误500内部服务器错误apache日志显示:
[Fri May 05 22:38:22.709307 2017] [:error] [pid 2750] [remote 18.189.13.77:36] mod_wsgi (pid=2750): Target WSGI script '/var/www/html/venv/testproject/testproject/wsgi.py' cannot be loaded as Python module.
[Fri May 05 22:38:22.709350 2017] [:error] [pid 2750] [remote 18.189.13.77:36] mod_wsgi (pid=2750): Exception occurred processing WSGI script '/var/www/html/venv/testproject/testproject/wsgi.py'.
[Fri May 05 22:38:22.709379 2017] [:error] [pid 2750] [remote 18.189.13.77:36] Traceback (most recent call last):
[Fri May 05 22:38:22.709406 2017] [:error] [pid 2750] [remote 18.189.13.77:36] File "/var/www/html/venv/testproject/testproject/wsgi.py", line 12, in <module>
[Fri May 05 22:38:22.709441 2017] [:error] [pid 2750] [remote 18.189.13.77:36] from django.core.wsgi import get_wsgi_application
[Fri May 05 22:38:22.709465 2017] [:error] [pid 2750] [remote 18.189.13.77:36] ImportError: No module named django.core.wsgi
服务器信息:
我按照网址(https://www.server-world.info/en/note?os=CentOS_7&p=httpd&f=20)的步骤操作,但直到最后一步才失败。
我的django in virtual env /var/www/html/venv/testproject/testproject/wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
application = get_wsgi_application()
我的Apache /etc/httpd/conf.d/django.conf:
WSGIDaemonProcess testapp python-path=/var/www/html/venv/testproject:/var/www/html/venv/lib/python3.6/site-packages
WSGIProcessGroup testapp
WSGIScriptAlias /django /var/www/html/venv/testproject/testproject/wsgi.py
<Directory /var/www/html/venv/testproject>
Require all granted
</Directory>
我跟着http://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#python-installation-in-use检查了系统环境。 /var/www/html/test_wsgi.py
import sys
def application(environ,start_response):
status = '200 OK'
output = ''
output += 'sys.version = %s\n' % repr(sys.version)
output += 'sys.prefix = %s\n' % repr(sys.prefix)
output += 'sys.path = %s\n' % repr(sys.path)
output += 'mod_wsgi.process_group = %s\n' % repr(environ['mod_wsgi.process_group'])
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
用户界面显示:
sys.version = '2.7.5 (default, Nov 6 2016, 00:28:07) \n[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]'
sys.prefix = '/usr'
sys.path = ['/var/www/html/venv/testproject', '/var/www/html/venv/lib/python3.6/site-packages', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages']
mod_wsgi.process_group = 'testapp'
权限:django.conf(777),防火墙端口启用80,443和8000
有谁能建议我如何修复它?喜欢在httpd / conf上设置任何配置?或者将任何python设置为sys.path?请尽量详细描述,因为我不熟悉它。