0
0 комментариев

Как правильно настроить связку python 3.4 + django + apache 2.2 + virtualenv?

Установлены python 2.7 и python 3.2, в виртуальном окружении установлен python 3.4. По 127.0.0.1:8000 сайт работает.

Как теперь открыть доступ извне для сайта?

Сейчас пытаюсь запустить чистый django, т.е. тестовую страницу.
Делаю так: запускаю апач в виртуальном окружении, он запускается без ошибок, пишет только:

Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

Запускаю runserver для django (использует python 3.4) — тестовая страница django открывается, а извне — ошибка 500.

Конфиг апача:

<VirtualHost *:80>
    ServerName  myproject
    ServerAdmin mail@list.ru
    WSGIScriptAlias / /var/www/myproject/src/myproject/myproject/django.wsgi
    WSGIDaemonProcess myproject processes=1 maximum-requests=1 threads=1
    WSGIProcessGroup myproject
    LogLevel debug
    ErrorLog /var/www/myproject/logs/myproject.error.log
    CustomLog /var/www/myproject/logs/myproject.access.log combined
    ServerSignature On
    <Directory "/var/www/myproject/src">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Стуктура проекта:

/var/www/myproject
 
..../static_content
 
..../src
 
......../myproject
 
............manage.py
 
............/myproject
 
...............django.wsgi  (использую сейчас)
 
...............settings.py
 
...............urls.py
 
...............wsgi.py (был изначально)
 
.../logs
 
.../env
 
......../bin
.............activate
.............activate.csh
.............activate.fish
.............django-admin
.............django-admin.py
.............easy_install
.............easy_install-3.4
.............pip
.............pip3
.............pip3.4
.............python -> python3.4
.............python3 -> python3.4
.............python3.4 -> /usr/local/opt/python-3.4.3/bin/python3.4
 
......../include
 
......../lib
 
......../docs

django.wsgi:

# -*- coding: utf-8 -*-
import os, sys, site
from django.core.wsgi import get_wsgi_application
sys.path.insert(0, os.path.dirname(__file__))
site.addsitedir('/var/www/myproject/env/lib/python3.4/sitepackages')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

wsgi.py (сейчас не используется, был изначально, с ним тоже не работало):

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
application = get_wsgi_application()

В логах апача пишется: [notice] Apache/2.2.22 (Debian) PHP/5.4.36-0+deb7u1 mod_wsgi/3.3 Python/3.2.3 configured -- resuming normal operations

В myproject.error.log:

[Tue Jul 28 19:04:22 2015] [info] mod_wsgi (pid=3770): Create interpreter 'myproject|'.
[Tue Jul 28 19:04:22 2015] [info] [client ::1] mod_wsgi (pid=3770, process='myproject', application='myproject|'): Loading WSGI script '/var/www/myproject/src/myproject/myproject/django.wsgi'.
[Tue Jul 28 19:04:22 2015] [error] [client ::1] mod_wsgi (pid=3770): Target WSGI script '/var/www/myproject/src/myproject/myproject/django.wsgi' cannot be loaded as Python module.
[Tue Jul 28 19:04:22 2015] [error] [client ::1] mod_wsgi (pid=3770): Exception occurred processing WSGI script '/var/www/myproject/src/myproject/myproject/django.wsgi'.
[Tue Jul 28 19:04:22 2015] [error] [client ::1] Traceback (most recent call last):
[Tue Jul 28 19:04:22 2015] [error] [client ::1]   File "/var/www/myproject/src/myproject/myproject/django.wsgi", line 7, in <module>
[Tue Jul 28 19:04:22 2015] [error] [client ::1]     from django.core.wsgi import get_wsgi_application
[Tue Jul 28 19:04:22 2015] [error] [client ::1] ImportError: No module named django.core.wsgi
[Tue Jul 28 19:04:22 2015] [info] mod_wsgi (pid=3770): Maximum requests reached 'myproject'.
[Tue Jul 28 19:04:22 2015] [info] mod_wsgi (pid=3770): Shutdown requested 'myproject'.
[Tue Jul 28 19:04:22 2015] [info] mod_wsgi (pid=3770): Stopping process 'myproject'.
[Tue Jul 28 19:04:22 2015] [info] mod_wsgi (pid=3770): Destroying interpreters.
[Tue Jul 28 19:04:22 2015] [info] mod_wsgi (pid=3770): Destroy interpreter 'myproject|'.
[Tue Jul 28 19:04:22 2015] [debug] mod_deflate.c(700): [client ::1] Zlib: Compressed 614 to 376 : URL /
[Tue Jul 28 19:04:22 2015] [info] mod_wsgi (pid=3770): Cleanup interpreter ''.
[Tue Jul 28 19:04:22 2015] [info] mod_wsgi (pid=3770): Terminating Python.
[Tue Jul 28 19:04:22 2015] [info] mod_wsgi (pid=3770): Python has shutdown.
[Tue Jul 28 19:04:23 2015] [info] mod_wsgi (pid=3854): Attach interpreter ''.
[Tue Jul 28 19:04:23 2015] [info] mod_wsgi (pid=3854): Create interpreter 'myproject|'.
[Tue Jul 28 19:04:23 2015] [info] [client ::1] mod_wsgi (pid=3854, process='myproject', application='myproject|'): Loading WSGI script '/var/www/myproject/src/myproject/myproject/django.wsgi'.
[Tue Jul 28 19:04:23 2015] [error] [client ::1] mod_wsgi (pid=3854): Target WSGI script '/var/www/myproject/src/myproject/myproject/django.wsgi' cannot be loaded as Python module.
[Tue Jul 28 19:04:23 2015] [error] [client ::1] mod_wsgi (pid=3854): Exception occurred processing WSGI script '/var/www/myproject/src/myproject/myproject/django.wsgi'.
[Tue Jul 28 19:04:23 2015] [error] [client ::1] Traceback (most recent call last):
[Tue Jul 28 19:04:23 2015] [error] [client ::1]   File "/var/www/myproject/src/myproject/myproject/django.wsgi", line 7, in <module>
[Tue Jul 28 19:04:23 2015] [error] [client ::1]     from django.core.wsgi import get_wsgi_application
[Tue Jul 28 19:04:23 2015] [error] [client ::1] ImportError: No module named django.core.wsgi
[Tue Jul 28 19:04:23 2015] [info] mod_wsgi (pid=3854): Maximum requests reached 'myproject'.
[Tue Jul 28 19:04:23 2015] [debug] mod_deflate.c(700): [client ::1] Zlib: Compressed 614 to 376 : URL /favicon.ico
[Tue Jul 28 19:04:23 2015] [info] mod_wsgi (pid=3854): Shutdown requested 'myproject'.
[Tue Jul 28 19:04:23 2015] [info] mod_wsgi (pid=3854): Stopping process 'myproject'.
[Tue Jul 28 19:04:23 2015] [info] mod_wsgi (pid=3854): Destroying interpreters.
[Tue Jul 28 19:04:23 2015] [info] mod_wsgi (pid=3854): Destroy interpreter 'myproject|'.
[Tue Jul 28 19:04:23 2015] [info] mod_wsgi (pid=3854): Cleanup interpreter ''.
[Tue Jul 28 19:04:23 2015] [info] mod_wsgi (pid=3854): Terminating Python.
[Tue Jul 28 19:04:23 2015] [info] mod_wsgi (pid=3854): Python has shutdown.
[Tue Jul 28 19:04:24 2015] [info] mod_wsgi (pid=3860): Attach interpreter ''.


Добавить комментарий