2014-01-27 77 views
0

我試圖讓我的應用在Debug=True模式下在VPS上啓動。Django + Apache + mod_wsgi =錯誤請求(400)

我在Python 2.7中使用Django 1.6。

我嘗試了簡單的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

希望任何指針和想法,因爲我現在已經基本退出的選項。

回答

0

這不會一開始工作:

activate_env=os.path.expanduser("~/.virtualenvs/myenv/bin/activate_this.py") 

這是因爲Apache運行於一個特殊的用戶和〜不會擴大到自己的用戶,其中的virtualenv是設置。

不知道這是否相關。