Django - 无法使用python 3.4在virtualenv中使用mod_wsgi进行部署

时间:2016-11-09 17:50:33

标签: django apache python-3.x mod-wsgi

我已经尝试了两天仍然无法使用python3.4将我的django proj部署到virtualenv中的apache + mod_wsgi-express。我在Web浏览器上收到内部服务器错误。请帮忙~~~

注意:我正在使用操作系统Apache 2.4.10运行mod_wsgi

在终端,我使用以下命令运行mod_wsgi-express:

(env3.4)root@X110:/var/www/html/example.com/mysite# mod_wsgi-express start-server --host 192.168.1.110 --port 8000 --working-directory mysite --application-type module mysite.wsgi --user developer --group developer
Server URL         : http://192.168.1.110:8000/
Server Root        : /tmp/mod_wsgi-192.168.1.110:8000:0
Server Conf        : /tmp/mod_wsgi-192.168.1.110:8000:0/httpd.conf
Error Log File     : /tmp/mod_wsgi-192.168.1.110:8000:0/error_log (warn)
Request Capacity   : 5 (1 process * 5 threads)
Request Timeout    : 60 (seconds)
Startup Timeout    : 15 (seconds)
Queue Backlog      : 100 (connections)
Queue Timeout      : 45 (seconds)
Server Capacity    : 20 (event/worker), 20 (prefork)
Server Backlog     : 500 (connections)
Locale Setting     : C.UTF-8

错误日志:

[Thu Nov 10 01:05:11.682936 2016] [wsgi:error] [pid 4692:tid 139781773657856] [remote 192.168.1.10:54805] mod_wsgi (pid=4692): Target WSGI script '/tmp/mod_wsgi-192.168.1.110:8000:0/handler.wsgi' cannot be loaded as Python module.
[Thu Nov 10 01:05:11.683051 2016] [wsgi:error] [pid 4692:tid 139781773657856] [remote 192.168.1.10:54805] mod_wsgi (pid=4692): Exception occurred processing WSGI script '/tmp/mod_wsgi-192.168.1.110:8000:0/handler.wsgi'.
[Thu Nov 10 01:05:11.683109 2016] [wsgi:error] [pid 4692:tid 139781773657856] [remote 192.168.1.10:54805] Traceback (most recent call last):
[Thu Nov 10 01:05:11.683194 2016] [wsgi:error] [pid 4692:tid 139781773657856] [remote 192.168.1.10:54805]   File "/tmp/mod_wsgi-192.168.1.110:8000:0/handler.wsgi", line 94, in <module>
[Thu Nov 10 01:05:11.683213 2016] [wsgi:error] [pid 4692:tid 139781773657856] [remote 192.168.1.10:54805]     recorder_directory=recorder_directory)
[Thu Nov 10 01:05:11.683266 2016] [wsgi:error] [pid 4692:tid 139781773657856] [remote 192.168.1.10:54805]   File "/var/www/html/example.com/env3.4/lib/python3.4/site-packages/mod_wsgi/server/__init__.py", line 1335, in __init__
[Thu Nov 10 01:05:11.683290 2016] [wsgi:error] [pid 4692:tid 139781773657856] [remote 192.168.1.10:54805]     __import__(entry_point)
[Thu Nov 10 01:05:11.683323 2016] [wsgi:error] [pid 4692:tid 139781773657856] [remote 192.168.1.10:54805] ImportError: No module named 'mysite'

=============================================== =============

以下是我的设置。

操作系统

os: debian 8.6.0
ip address: 192.168.1.110
apt-get install build-essential
apt-get install libssl-dev
apt-get install apache2-threaded-dev
apt-get install python-dev
apt-get install libmysqlclient-dev
apt-get install python-virtualenv 

使用python 3.4创建了virtualenv

virtualenv env3.4 --python=python3.4

在virtualenv中,我用pip安装了以下内容:

pip install django #django 1.10.3
pip install -U setuptools
pip install mysqlclient
pip install djangorestframework
pip install django-filter
pip install httpie
pip install coreapi (to include api schema)
pip install coreapi-cli (client)
pip install mod_wsgi

项目结构:

/var/www/html/example.com/mysite
                           +mysite
                               settings.py
                               urls.py
                               wsgi.py
                           +app1
                           +app2

settings.py

ALLOWED_HOSTS = ['192.168.1.110']

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    .....
    'rest_framework',
    'mod_wsgi.server',
]
....
WSGI_APPLICATION = 'mysite.wsgi.application'

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

application = get_wsgi_application()

0 个答案:

没有答案