django + mod_wsgi

时间:2016-03-02 15:02:36

标签: python django apache ubuntu mod-wsgi

我在本地开发服务器上有一个正常运行的Django应用程序,但是当将其解压缩到Apache + mod_wsgi设置时,网址似乎无法正确解析,即无法加载已安装应用程序中的url模块。我已经调试了很长一段时间了,非常感谢一些帮助。

apache日志中实际上没有真正的错误消息,因此可能会有一些无限循环,但我不知道在哪里或为什么。很长一段时间后,请求以错误代码500和日志消息结束:"守护程序进程死锁计时器到期,停止进程'天津'。"我发现url import是痛苦的调试和打印语句的问题,并意识到这是应用程序卡住的地方。堆栈是这样的,其中 import (name)永远不会返回,名称为" Tianjin.urls"。

import_module [__init__.py:37]  
urlconf_module [urlresolvers.py:396]    
url_patterns [urlresolvers.py:402]  
resolve [urlresolvers.py:366]   
get_response [base.py:119]      

我的设置:

  • Linux 4.2.0-27-generic#32-Ubuntu SMP x86_64 GNU / Linux
  • Apache / 2.4.12(Ubuntu)Server MPM:forked threaded
  • Python 2.7在项目文件夹中名为env的虚拟环境中
  • mod_wsgi-4.4.21,源自
  • Django 1.8.5

/ home / TianjinAdmin /中的目录结构:

-IRIS
  -env
    -..
  -Tianjin
    - __init__.py
    - celery.py
    - settins.py
    - urls.py
    - wsgi.py
  -TianjinUI
    - __init__.py
    - admin.py
    - models.py
    - tests.py
    - urls.py
    - views.py
  -TianjinBE
    - ...
  - manage.py

Apache虚拟主机配置:

<VirtualHost *:80>

        ServerAdmin bla@gmail.com
        DocumentRoot /var/www/html

        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Alias /static /home/TianjinAdmin/IRIS/templates/TianjinUI/app
        <Directory /home/TianjinAdmin/IRIS/templates/TianjinUI/app>
            Require all granted
        </Directory>

       <Directory /home/TianjinAdmin/IRIS/Tianjin>
           <Files wsgi.py>
               Require all granted
           </Files>
       </Directory>

       WSGIDaemonProcess Tianjin python-path=/home/TianjinAdmin/IRIS:/home/TianjinAdmin/IRIS/env/lib/python2.7/site-packages processes=2 threads=15 display-name=%{GROUP}
       WSGIProcessGroup Tianjin
       WSGIScriptAlias / /home/TianjinAdmin/IRIS/Tianjin/wsgi.py

</VirtualHost>

津/ wsgi.py

import os, sys

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Tianjin.settings")
#tried with and without the following two lines
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))

print >> sys.stderr, sys.path
application = get_wsgi_application()

天津的相关内容/ settings.py:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #'kombu.transport.django',
    'kombu.transport.django.KombuAppConfig',
    'djcelery',
    'TianjinBE',
    'TianjinUI',
 )
ROOT_URLCONF = 'Tianjin.urls'

津/ urls.py

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^ui/', include('TianjinUI.urls')),
    url(r'^oauth/', include('TianjinBE.urls')),
    url(r'^admin/', include(admin.site.urls)),
]

1 个答案:

答案 0 :(得分:0)

原来,它与我的配置无关。隐藏在日志中并且有时吞下的某处是警告“Matplotlib正在使用fc-list构建字体缓存。这可能需要一些时间。”所以我有一个用于matplot的第三方python库阻止了应用程序。似乎是因为缓存文件存在一些权限问题,请参阅matplotlib taking time when being imported