1

Debianシステムでapache2 + mod_wsgiを使用してdjangoサーバー(1.4、python 2.7)をセットアップしています。django 側からは、すべてが完璧に機能します。manage.py runserver を実行すると、開発サーバーはサイトを正しく表示しますが、WSGI を実行するように Apache サーバーをセットアップしようとすると、ValueError の表示に失敗します。

これはmysite.wsgi です

ALLDIRS = ['/usr/local/lib/python2.7/site-packages']
# the above directory depends on the location of your python installation.
# if using virtualenv, it will need to match your projects locale.
import os
import sys
import site

os.environ['DJANGO_SETTINGS_MODULE'] = 'ggDatabase.settings'
prev_sys_path = list(sys.path)
sys.path.append("/usr/local/lib/python2.7")
path = "/home/acad/statsdb/src"
if path not in sys.path:
        sys.path.append(path)
        sys.path.append("/home/acad/statsdb/src/ggDatabase")
for directory in ALLDIRS:
        site.addsitedir(directory)
        new_sys_path = []
        for item in list(sys.path):
            if item not in prev_sys_path:
                new_sys_path.append(item)
                sys.path.remove(item)
                sys.path[:0] = new_sys_path

# change this depending on your project.

site.addsitedir("/home/acad/statsdb/src/ggDatabase/")


os.environ['PYTHON_EGG_CACHE'] = '/home/acad/.python-eggs'
os.environ['SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

これはapache VirtualHost 構成です:

<VirtualHost 127.0.0.1:8000>
    ServerName mysite.com
    ServerAlias www.mysite.com
    <Directory /home/acad/statsdb/src/ggDatabase>
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn
    CustomLog /var/log/apache2/mysite.com.access.log combined
    ErrorLog /var/log/apache2/mysite.com.error.log

    WSGIDaemonProcess mysite.com user=acad group=acad threads=25 python-path=/usr/local/lib/python2.7
    WSGIProcessGroup mysite.com
    WSGIScriptAlias / /home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi

</VirtualHost>

これは私のテスト サーバーでの正確な構成であり、そこで動作しますが、wsgi スクリプトを実行しようとすると、新しいサーバーで問題が発生します。

[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] mod_wsgi (pid=26233): Target WSGI script '/home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi' cannot be loaded as Python module.
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] mod_wsgi (pid=26233): Exception occurred processing WSGI script '/home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi'.
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]   File "/home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi", line 31, in <module>
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]     import django.core.handlers.wsgi
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 8, in <module>
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]     from django import http
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/site-packages/django/http/__init__.py", line 11, in <module>
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]     from urllib import urlencode, quote
 [Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/urllib.py", line 1228, in <module>
 [Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]     _safe_map[c] = c if (i < 128 and c in always_safe) else '%{:02X}'.format(i)
 [Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] ValueError: zero length field name in format

エラーは非常に一般的であるため、何が問題なのか本当にわかりません。何か案は?

前もって感謝します!

ブルーノ

4

1 に答える 1

0

Solved it. If someone has similar errors, make sure to print sys.version, you may find out (as I did) that wsgi was configured under another installed python version.

If that's the case, reinstall mod_wsgi with the --with-python option.

于 2012-06-29T20:03:47.063 に答える