[英]Django + Apache + mod_wsgi = Bad Request (400)
我正在尝试以Debug=True
模式在VPS上启动我的应用程序。
我正在将Django 1.6与Python 2.7结合使用。
我尝试了简单的wscgi脚本,发现它对浏览器运行良好(基本上在文本/纯文本中返回200和“ Hello world”)。 这是我的配置:
虚拟主机配置
<VirtualHost *:80>
ServerName subdomain.domain.info
ServerAlias www.subdomain.sigizmund.info
WSGIScriptAlias / /var/www/subdomain/index.wsgi
Alias /static/ /var/www/subdomain/static/
ErrorLog /tmp/subdomain.error.log
CustomLog /tmp/subdomain.custom.log common
LogLevel debug
<Location "/static/">
Options -Indexes
</Location>
<Directory /home/sgzmd/code/myproject>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
index.wsgi
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/sgzmd/.virtualenvs/myenv/local/lib/python2.7/site-packages')
PROJECT_PATH = '/home/sgzmd/code/myproject'
if PROJECT_PATH not in sys.path:
sys.path.insert(0, PROJECT_PATH)
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
# Activate your virtual env
activate_env=os.path.expanduser("~/.virtualenvs/myenv/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
import django.core.handlers.wsgi
import cStringIO
import pprint
class LoggingMiddleware:
def __init__(self, application):
self.__application = application
def __call__(self, environ, start_response):
errors = environ['wsgi.errors']
pprint.pprint(('REQUEST', environ), stream=errors)
def _start_response(status, headers, *args):
pprint.pprint(('RESPONSE', status, headers), stream=errors)
return start_response(status, headers, *args)
return self.__application(environ, _start_response)
application = LoggingMiddleware(django.core.handlers.wsgi.WSGIHandler())
我有以下日志记录输出: http ://pastebin.com/SnZVEeT1(来自LoggingMiddleware)和/var/log/django/error.log
在创建和重新创建时仍然完全为空。
我通过编辑项目的settings.py来确定该应用正在加载,其内容可在此处找到: http : //pastebin.com/Byr8RStb
我们将不胜感激任何指尖和想法,因为我现在基本上已经没有选择了。
一开始这是行不通的:
activate_env=os.path.expanduser("~/.virtualenvs/myenv/bin/activate_this.py")
这是因为Apache以特殊用户身份运行,而〜不会扩展到设置了virtualenv的您自己的用户。
不知道这是否相关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.