Django + Apache + Mod_wsgi 导致 500 内部服务器错误(附日志)
Django + Apache + Mod_wsgi cuasing 500 Internal Server Error (log attached)
Django WSGI Script Won't load due to a Python issue
研究了一天,还是没有解决问题。
服务器在线,正在使用站点 virtulenv
Windows 8-64 位,python34,Wamp 服务器 apache 64 位
内部会议:
Listen 8080
NameVirtualHost 127.0.0.1:8080
<VirtualHost *:8080>
ServerAdmin admin@hotmail.com
ServerName 192.168.0.101:8080
DocumentRoot "C:/wamp/www/venv/testweb10/testweb10"
</VirtualHost>
WSGIScriptAlias / "C:/wamp/www/venv/testweb10/testweb10/wsgi.py"
WSGIPythonPath "C:/wamp/www/venv/Lib/site-packages"
<Directory "C:/wamp/www/venv/testweb10">
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
Settings.py
DEBUG = True
ALLOWED_HOSTS = ['testweb10']
主机
127.0.0.1 testweb10
我怀疑 python 兼容性问题
用户变量路径:
C:\WINDOWS\system32;C:\Python34;C:\Python34\python.exe;C:\Python34\Scripts;C:\Python34\Lib\site-packages\django\bin;
请帮忙
您的 wsgi.py 中是否有对您的 virtualenv 的引用?这是我在 Linux 上使用的模板,例如:
import site
site.addsitedir('/home/mysite/venv/lib/python2.7/site-packages')
import os
import sys
sys.path.append('/home/mysite/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
顺便说一句,这是 Django 1.6。 Django 1.7 在 wsgi.py
中有一些差异
对于 Django 1.7,最后两行是:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
WSGIPythonPath 必须包含项目的根目录。
Used to specify additional directories to search for Python modules.
If multiple directories are specified they should be separated by a
':' if using a UNIX like system, or ';' if using Windows.
WSGIPythonPath = "C:/wamp/www/venv/testweb10/testweb10;C:/wamp/www/venv/Lib/site-packages"
最终以下似乎适用于 Django 1.8
import site
site.addsitedir("C:/Python34/Lib/site-packages")
import os
import sys
sys.path.append("C:/wamp/www/venv/testweb10/testweb10")
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "testweb10.settings"
application = get_wsgi_application()
但是现在出现错误:(
[mpm_winnt:通知] [pid 3788:tid 688] AH00455:Apache/2.4.9 (Win64) mod_wsgi/4.4.10 Python/3.4.3 PHP/5。 5.12配置--恢复正常运行
对于有同样问题的人:
一些建议(也给自己):
每个组件的版本都很重要
1) 以干净的方式安装 Appache 或 Wamp 服务器。确保删除其旧的注册表编辑器。
2) 获取 Mod_WSGI 并仔细按照安装说明操作!!!
2.5) 测试 Mod_WSGI 是否在没有 Django
的情况下正常工作
3) 最后一步是安装 python、Django,并设置环境和配置文件。
4) 测试和部署
Django WSGI Script Won't load due to a Python issue
研究了一天,还是没有解决问题。 服务器在线,正在使用站点 virtulenv Windows 8-64 位,python34,Wamp 服务器 apache 64 位
内部会议:
Listen 8080
NameVirtualHost 127.0.0.1:8080
<VirtualHost *:8080>
ServerAdmin admin@hotmail.com
ServerName 192.168.0.101:8080
DocumentRoot "C:/wamp/www/venv/testweb10/testweb10"
</VirtualHost>
WSGIScriptAlias / "C:/wamp/www/venv/testweb10/testweb10/wsgi.py"
WSGIPythonPath "C:/wamp/www/venv/Lib/site-packages"
<Directory "C:/wamp/www/venv/testweb10">
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
Settings.py
DEBUG = True
ALLOWED_HOSTS = ['testweb10']
主机
127.0.0.1 testweb10
我怀疑 python 兼容性问题
用户变量路径:
C:\WINDOWS\system32;C:\Python34;C:\Python34\python.exe;C:\Python34\Scripts;C:\Python34\Lib\site-packages\django\bin;
请帮忙
您的 wsgi.py 中是否有对您的 virtualenv 的引用?这是我在 Linux 上使用的模板,例如:
import site
site.addsitedir('/home/mysite/venv/lib/python2.7/site-packages')
import os
import sys
sys.path.append('/home/mysite/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
顺便说一句,这是 Django 1.6。 Django 1.7 在 wsgi.py
中有一些差异对于 Django 1.7,最后两行是:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
WSGIPythonPath 必须包含项目的根目录。
Used to specify additional directories to search for Python modules. If multiple directories are specified they should be separated by a ':' if using a UNIX like system, or ';' if using Windows.
WSGIPythonPath = "C:/wamp/www/venv/testweb10/testweb10;C:/wamp/www/venv/Lib/site-packages"
最终以下似乎适用于 Django 1.8
import site
site.addsitedir("C:/Python34/Lib/site-packages")
import os
import sys
sys.path.append("C:/wamp/www/venv/testweb10/testweb10")
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "testweb10.settings"
application = get_wsgi_application()
但是现在出现错误:( [mpm_winnt:通知] [pid 3788:tid 688] AH00455:Apache/2.4.9 (Win64) mod_wsgi/4.4.10 Python/3.4.3 PHP/5。 5.12配置--恢复正常运行
对于有同样问题的人:
一些建议(也给自己):
每个组件的版本都很重要
1) 以干净的方式安装 Appache 或 Wamp 服务器。确保删除其旧的注册表编辑器。
2) 获取 Mod_WSGI 并仔细按照安装说明操作!!!
2.5) 测试 Mod_WSGI 是否在没有 Django
的情况下正常工作3) 最后一步是安装 python、Django,并设置环境和配置文件。
4) 测试和部署