Results 1 to 4 of 4

Thread: Trying to Understand django deployment in Apache - WSGI

  1. #1
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,469
    Blog Entries
    2

    Default Trying to Understand django deployment in Apache - WSGI

    Hoping someone has experience deploying django or an app like it in Apache (someone with experience deploying a Java website <might> be able to provide some insight although django is a python app)

    Setup:
    Installed
    openSUSE 13.1/LXDE
    Apache 2.4
    mod_wsgi (from the OSS)

    Configuration:
    Added the following line to the top of /etc/apache2/httpd.conf
    Code:
    LoadModule wsgi_module /usr/lib64/apache2/mod_wsgi.so
    Created an /etc/apache2/httpd.conf.local which should contain custom commands modifying httpd.conf
    Added the following line to /etc/apache2/httpd.conf.local
    Code:
     WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi
    The contents of graphite.wsgi, should be pretty typical... It should import settings from various configs to build and point apache to the django app which is in a different location than the default web root.
    Code:
    # cat /opt/graphite/conf/graphite.wsgi
    import os, sys
    sys.path.append('/opt/graphite/webapp')
    os.environ['DJANGO_SETTINGS_MODULE'] = 'graphite.settings'
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    # READ THIS
    # Initializing the search index can be very expensive, please include
    # the WSGIScriptImport directive pointing to this script in your vhost
    # config to ensure the index is preloaded before any requests are handed
    # to the process.
    from graphite.logger import log
    log.info("graphite.wsgi - pid %d - reloading search index" % os.getpid())
    import graphite.metrics.search
    Problem:
    Apache is ignoring the django settings exposed by wsgi and continues to point to the default web root (/srv/www/htdocs)

    Question:
    Is there something <specific> (hopefully) I can look at that is supposed to re-direct the web root? From what I understand, Apache is supposed to come installed with default settings and only if no additional settings are imported then the default settings are used. I should not need to modify the default settings to disable them.

    Maybe I should be doing something in a vhosts config somewhere although I'm deploying just this one instance?

    TIA,
    TSU

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,382

    Default Re: Trying to Understand django deployment in Apache - WSGI

    In my system apache uses not httpd.conf, but default-server.conf as it's main configuration file.
    Henk van Velden

  3. #3
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,469
    Blog Entries
    2

    Default Re: Trying to Understand django deployment in Apache - WSGI

    From what I've read and so far implemented (works), httpd.conf is still important since it does successfully load modules.

    Also, from what I've read, default-server.conf is supposed to be the system's default server config, if you're going to modify how Apache works you're not supposed to modify this file unless you really want "the defaults" to be different.

    WSGI is an approach similar to what I've seen with Java containers where Apache is directed to deploy a website (or more than one) by re-directing to a new webroot complete with its own app configuration which can be very complex, so it should not be any surprise to see the default web root empty.

    WSGI is also not an Apache-specific technology, I'm also currently looking at how it's implemented with nginx in case I can't get a certain answer why it's failing with Apache for me. Cherokee is also supposed to be a webserver with strong integrated support for WSGI.

    But, in all its complexity I'm unclear exactly where this re-direction is controlled.
    I hope I won't have to devote an entire day (likely more) to learning WSGI from the ground up when I don't know how often I'll encounter it (although according to the documentation they believe they will become a very popular and common way to deploy web apps).

    TSU

  4. #4
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,469
    Blog Entries
    2

    Default Re: Trying to Understand django deployment in Apache - WSGI

    A follow up.

    First, the importance of WSGI.
    For anyone who installs and runs any kind of Python web app on a webserver configured for virtual websites, WSGI (WebServerGatewayInterface) is needed. This applies not only to Apache, but most other popular webservers as well.

    As of today, IMO the official documentation at Django and WSGI are sorely lacking. Someone new to WSGI likely won't get anywhere, the Django documentation might be detailed and complete but without any guidance how to configure and setup (IMO). The official WSGI documentation simply points to a few things (including broken links) but again won't likely help much. For both of these, I can see if you <already> know how WSGI works, then they can be used as references to find things.

    But, for newbies I'd recommend the following YouTube video (33 minutes). Very basic, although describes how to setup on Ubuntu it should be useful for anyone setting up on openSUSE as well (using slightly different commands).
    http://www.youtube.com/watch?v=hBMVVruB9Vs

    TSU

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •