[英]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.