我正在尝试设置Apache2以使用mod_wsgi连接到Django。
我有一个本地开发服务器设置运行apache2来为网站提供大部分文件。但是,我希望使用Django提供联系页面,因为我有一个Django应用程序是一个联系表单。
我也使用virtualenv作为python路径。
我已按照Django项目文档中的说明进行操作。
我的文件夹结构是:
-mysite.com
-myproject
-contactApp
-myproject
-env
mysite.com.conf
<Directory /home/user/Documents/webdev/mysite.com/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess mysite.com python-home=/home/user/Documents/webdev/mysite.com/myproject/env python-path=/home/user/Documents/webdev/mysite.com/myproject/env/lib/python3.5/site-packages
WSGIProcessGroup mysite.com
WSGIScriptAlias /contact /home/user/Documents/webdev/mysite.com/myproject/myproject/wsgi.py process-group=mysite.com
当我尝试访问mysite.com/contact时,我遇到的问题是500内部服务器错误
apache error.log会出现以下错误:
[Mon Jun 12 23:03:09.649249 2017] [wsgi:error] [pid 25755:tid 139706287081216['/home/user/Documents/webdev/mysite.com/myproject/env/lib/python35.zip', '/home/user/Documents/webdev/mysite.com/myproject/env/lib/python3.5', '/home/user/Documents/webdev/mysite.com/myproject/env/lib/python3.5/plat-x86_64-linux-gnu', '/home/user/Documents/webdev/mysite.com/myproject/env/lib/python3.5/lib-dynload', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/home/user/Documents/webdev/mysite.com/myproject/env/lib/python3.5/site-packages']
[Mon Jun 12 23:03:09.649846 2017] [wsgi:error] [pid 25755:tid 139706287081216] [remote 127.0.0.1:39990] mod_wsgi (pid=25755): Target WSGI script '/home/user/Documents/webdev/mysite.com/myproject/myproject/wsgi.py' cannot be loaded as Python module.
[Mon Jun 12 23:03:09.649925 2017] [wsgi:error] [pid 25755:tid 139706287081216] [remote 127.0.0.1:39990] mod_wsgi (pid=25755): Exception occurred processing WSGI script '/home/user/Documents/webdev/mysite.com/myproject/myproject/wsgi.py'.
[Mon Jun 12 23:03:09.650380 2017] [wsgi:error] [pid 25755:tid 139706287081216] [remote 127.0.0.1:39990] Traceback (most recent call last):
[Mon Jun 12 23:03:09.650450 2017] [wsgi:error] [pid 25755:tid 139706287081216] [remote 127.0.0.1:39990] File "/home/user/Documents/webdev/mysite.com/myproject/myproject/wsgi.py", line 14, in <module>
[Mon Jun 12 23:03:09.650462 2017] [wsgi:error] [pid 25755:tid 139706287081216] [remote 127.0.0.1:39990] from django.core.wsgi import get_wsgi_application
[Mon Jun 12 23:03:09.650512 2017] [wsgi:error] [pid 25755:tid 139706287081216] [remote 127.0.0.1:39990] ImportError: No module named 'django'
要检查我的virtualenv是否出错,我尝试使用virtualenv导入django并且导入正常。
我的wsgi.py文件是在启动一个新的django项目时自动生成的文件,即
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
application = get_wsgi_application()
任何人都可以帮我诊断问题,因为我试图寻找解决方案,但没有人帮助过?感谢。