Question

I've built a django site for managing some of the data rstudio and rapache use. I'd like to deploy it to the same box, either on a different port or on a different directory, but my knowledge in this area is a day old and the documentation combined with experimenting have not yielded results.

When I try to access the link http://internalboxname:8000 or http://internalboxname:8000/django it eventually says the page can't be returned. The apache error log does not contain any details.

I'm hoping that someone can point me to the crucial bit of documentation I missed, and/or tell me where I'm going wrong


Background

I have a setup like:

  • Rstudio set to port 80 using its conf file
  • Rapache running on the sites-enabled/000-default VirtualHost (contents included below)
  • Created file sites-enabled/django VirtualHost (contents included below)
  • django project at /usr/local/.../python/app
  • A wsgi.py file created by the app generation process in /usr/local/.../python/app

Installed versions:

  • Ubuntu 12.04LTS
  • Apache 2.2.22-1ubuntu1.6
  • python 2.7
  • libapache2-mod-wsgi 3.3-4build1

sites-enabled/000-default (most of this was already here, only changes I made were port number and /RapacheInfo location)

<VirtualHost *:8080>
        ServerAdmin webmaster@localhost

<Location /RApacheInfo>
SetHandler r-info
</Location>

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

sites-enabled/django

WSGIScriptAlias / /usr/local/.../python/app/app/wsgi.py
WSGIPythonPath /usr/local/.../python/app/app   
<VirtualHost *:8000>

<Directory /usr/local/.../python/app/app>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>

wsgi.py

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Was it helpful?

Solution 2

  1. Implement virtualenv!
  2. Configure apache so that the python path is outside the virtual host
  3. Update wsgi.py to reference virtualenv path

/etc/apache2/sites-enabled/000-default

WSGIPythonPath /usr/local/django-user/app/:/usr/local/django-user/lib/python2.7/site-packages/

<VirtualHost *:8000>
ServerAdmin webmaster@localhost
ServerName localserver
WSGIScriptAlias / /usr/local/django-user/app/app/wsgi.py
AliasMatch ^/([^/]*\.css) /usr/local/django-user/app/static/styles/$1
Alias /static/ /usr/local/django-user/app/static/
        <Directory /usr/local/django-user/app/app>
        <Files wsgi.py>
        Order deny,allow #Apache version dependent
        allow from all #Apache version dependent
        </Files>
</Directory>
...

wsgi.py

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/usr/local/django-user/lib/python2.7/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('/app)
sys.path.append('/app/app)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

# Activate your virtual env
activate_env=os.path.expanduser("/usr/local/django-user/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

OTHER TIPS

Do you get an Apache erro page?

Did you try including the WSGI directives insde the VirtualHost tag?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top