运行django和apache2 / mod_wsgi的问题。我一直收到500内部服务器错误。我已经尝试了许多修复工具的组合。任何帮助是极大的赞赏。这是我的设置:
Ubuntu 16.04
django 1.10.5
apache 2.4.18
python 3.4(virtualenv)
libapache2-mod-wsgi-py3
我的文件夹结构是:
/home/user/site/venv (virtualenv folder)
bin
include
lib
/home/user/site/mysite
|- manage.py
static
mysite
|__init__.py
|settings.py
|urls.py
|wsgi.py
site.conf
<VirtualHost *:80>
WSGIDaemonProcess myproject python-home=/home/user/site/venv python-path=/home/user/site/mysite
WSGIProcessGroup myproject
WSGIScriptAlias / /home/user/site/mysite/mysite/wsgi.py
Alias /static /home/user/site/mysite/static
<Directory /home/user/site/mysite/static>
Require all granted
</Directory>
<Directory /home/user/site/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
application = get_wsgi_application()
的apache2 / error.log中
[mpm_event:notice] [pid 8908:tid 140560009164672] AH00491: caught SIGTERM, shutting down
[wsgi:warn] [pid 9047:tid 139761898837888] mod_wsgi: Compiled for Python/3.5.1+.
[wsgi:warn] [pid 9047:tid 139761898837888] mod_wsgi: Runtime using Python/3.5.2.
[mpm_event:notice] [pid 9047:tid 139761898837888] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[core:notice] [pid 9047:tid 139761898837888] AH00094: Command line: '/usr/sbin/apache2'
[wsgi:error] [pid 9049:tid 139761776183040] mod_wsgi (pid=9049): Target WSGI script '/home/user/site/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[wsgi:error] [pid 9049:tid 139761776183040] mod_wsgi (pid=9049): Exception occurred processing WSGI script '/home/user/site/mysite/mysite/wsgi.py'.
[wsgi:error] [pid 9049:tid 139761776183040] Traceback (most recent call last):
[wsgi:error] [pid 9049:tid 139761776183040] File "/home/user/site/mysite/mysite/wsgi.py", line 12, in <module>
[wsgi:error] [pid 9049:tid 139761776183040] from django.core.wsgi import get_wsgi_application
[wsgi:error] [pid 9049:tid 139761776183040] ImportError: No module named 'django'
我已授予以下文件夹的权限:
sudo chown -R www-data:www-data /home/user/site/venv
sudo chown -R www-data:www-data /home/user/site/mysite
任何帮助或批评,我都会感谢您提前感谢。
答案 0 :(得分:4)
我到这里寻找最新版本:mod_wsgi_releases
务必使用
.configure --with-python=/your/virtualenv/bin/python(your python_verion here)
答案 1 :(得分:1)
尝试使用类似的东西。要确认一下,用户组是myproject
吗?
WSGISocketPrefix /var/run/wsgi
WSGIPythonPath /home/user/site/venv/lib/python2.7/site-packages
WSGIDaemonProcess ec2-user processes=1
WSGIProcessGroup ec2-user
WSGIScriptAlias / /home/user/site/mysite/mysite/wsgi.py
答案 2 :(得分:0)
在虚拟环境中尝试which django-admin
。如果这个位置与您希望使用的位置不同,请在虚拟环境中安装django。
要么
在你的虚拟环境中尝试pip freeze > requirements.txt
,看看django实际上就在那里。
答案 3 :(得分:0)
有同样的问题,我通过在项目中通过虚拟环境登录时卸载gunicorn并重新安装来解决了该问题