问题描述
运行django和apache2 / mod_wsgi的问题。我不断获得500内部服务器错误。我已经尝试过许多修复的组合,没有一个工作。任何帮助是极大的赞赏。这是我的设置:
Issues running django and apache2/mod_wsgi. I keep getting 500 Internal Server Error. I have tried many combinations of fixes to which none have worked. Any help is greatly appreciated. This is my setup:
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'
我已经授予以下文件夹的权限:
I have given the permissions to the folders below:
sudo chown -R www-data:www-data /home/user/site/venv
sudo chown -R www-data:www-data /home/user/site/mysite
任何帮助或批评我都会提前感谢您。
Any help or criticism I would love thank you in advance.
推荐答案
所以经过一些激烈的头撞在墙上。原来,我需要编译我自己的mod_wsgi为我使用的python版本。我正在使用ubuntu libapache2-mod-wsgi-py3的标准repo,它被编译为与我的error.log中显示的python3.5.2一起使用。
So after some intense head bashing against the wall. It turns out I needed to compile my own mod_wsgi for the version of python I was using. I was using the standard repo for ubuntu libapache2-mod-wsgi-py3 which is compiled to use with python3.5.2 as it shows in my error.log.
我在这里找到最新版本:
I went here for the most up to date version : mod_wsgi_releases
确保使用
.configure - -with-python = / your / virtualenv / bin / python(你的python_verion这里)
这篇关于500内部服务器错误mod_wsgi apache“importerror:否模块命名为'django'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!