Я пытался почти неделю, но не смог решить эту проблему, и не смог найти в Интернете ничего, что могло бы мне помочь.
У меня есть многодоменный сервер с Centos 5.3 и проект Django, который я должен развернуть. Я установил python 2.7 в /usr/local/python2.7 для работы с Django 1.3, также установил и включил mod_wsgi.
Следующим, что я сделал, была проверка этого проекта и создание virtualenv в домашнем каталоге пользователя, которому будет принадлежать это приложение. Я создал скрипт wsgi:
import os
import sys
import site
# path to domain specific virtual environment where python packages will be installed
site.addsitedir('/home/user/domain.com/project/env/lib/python2.7/site-packages')
sys.path.append('/home/user/domain.com/project/')
sys.path.append('/home/user/domain.com/project/application/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
и настроенный виртуальный хост.
<VirtualHost \
79.98.31.117:80\
>
ServerName masinis.lt
ServerAlias \
www.masinis.lt
DocumentRoot "/home/user/domain.com/"
WSGIScriptAlias / /home/user/domain.com/project/wsgi_script.wsgi
<Directory "/home/tomas/masinis.lt/liveopenly/">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Alias /static/ /home/user/domain.com/project/application/static/
<Directory "/home/user/domain.com/project/application/static/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
То, что я называю проектом, на самом деле является папкой для virtualenv, инструкций и самого приложения. Приложение в данном случае - это проект django - в нем есть приложения, настройки и другие элементы. Также он использует внешние приложения, которые хранятся в папке virtualenv.
Когда я пытаюсь добраться до domain.com, я получаю 500 ошибок. И error_log дает мне это:
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] mod_wsgi (pid=11655): Exception occurred processing WSGI script '/home/user/domain.com/project/masinis_lt.wsgi'.
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] Traceback (most recent call last):
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 273, in __call__
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] response = self.get_response(request)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/core/handlers/base.py", line 169, in get_response
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/core/handlers/base.py", line 218, in handle_uncaught_exception
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return callback(request, **param_dict)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/application/middleware.py", line 44, in server_error
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return HttpResponseServerError(t.render(Context({'MEDIA_URL': settings.MEDIA_URL})))
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 123, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return self._render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 117, in _render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return self.nodelist.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 744, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] bits.append(self.render_node(node, context))
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 757, in render_node
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return node.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/loader_tags.py", line 127, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return compiled_parent._render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 117, in _render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return self.nodelist.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 744, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] bits.append(self.render_node(node, context))
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 757, in render_node
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return node.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/loader_tags.py", line 127, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return compiled_parent._render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 117, in _render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return self.nodelist.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 744, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] bits.append(self.render_node(node, context))
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django/template/base.py", line 757, in render_node
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] return node.render(context)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django_static/templatetags/django_static.py", line 208, in render
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] symlink_if_possible=self.symlink_if_possible)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django_static/templatetags/django_static.py", line 493, in _static_file
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] _mkdir(os.path.dirname(new_filepath))
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django_static/templatetags/django_static.py", line 624, in _mkdir
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] _mkdir(head)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django_static/templatetags/django_static.py", line 624, in _mkdir
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] _mkdir(head)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] File "/home/user/domain.com/project/env/lib/python2.7/site-packages/django_static/templatetags/django_static.py", line 626, in _mkdir
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] os.mkdir(newdir)
[Mon Feb 27 00:40:10 2012] [error] [client 78.63.254.43] OSError: [Errno 13] Permission denied: 'static'
Когда я пытаюсь запустить в режиме разработки (manage.py runserver), все работает, но похоже, что статический файл не найден при доступе к странице. В то время как журнал сервера показывает 302 ответа ...
В чем может быть проблема?