lost and found ( for me ? )

apache + Django ( ubuntu 12.04 )

I am newbie to Django :D

many thanks.

root@ubuntu1204-vm4:~# python --version
Python 2.7.3
root@ubuntu1204-vm4:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.2 LTS
Release:        12.04
Codename:       precise

#  apt-get install apache2 libapache2-mod-wsgi python-setuptools python-pip

install Django
# pip install django
Successfully installed django
Cleaning up...

[ set up ]

create a directory
# mkdir /srv/www
# mkdir /srv/www/wsgi

put “app.wsgi” under /srv/www/wsgi directory.
# cat /srv/www/wsgi/app.wsgi
def application(environ, start_response):
   status = '200 OK'
   output = 'Hello World!'

   response_headers = [('Content-type', 'text/plain'),
                       ('Content-Length', str(len(output)))]
   start_response(status, response_headers)

   return [output]

enable a new site.
# cat /etc/apache2/sites-available/wsgi
<VirtualHost *:80>

   ServerName wsgi.djangoserver
   DocumentRoot /srv/www/wsgi

   <Directory /srv/www/wsgi>
       Order allow,deny
       Allow from all

   WSGIScriptAlias / /srv/www/wsgi/app.wsgi


enable “wsgi” site, disable “default” site and then restart apache2
# a2ensite wsgi

# a2dissite default

root@ubuntu1204-vm4:~# /etc/init.d/apache2 restart
* Restarting web server apache2

access to apache’s IP

make another project

make a new project
root@ubuntu1204-vm4:/srv/www# pwd
root@ubuntu1204-vm4:/srv/www# django-admin.py startproject test01
root@ubuntu1204-vm4:/srv/www# mkdir /srv/www/test01/apache

# cat /srv/www/test01/apache/django.wsgi
import os
import sys


os.environ['DJANGO_SETTINGS_MODULE'] = 'test01.settings'

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

enable a new site called “test01”
# cat /etc/apache2/sites-available/test01
# cat /etc/apache2/sites-available/test01
<VirtualHost *:80>

   ServerName test01.djangoserver
   DocumentRoot /srv/www/test01

   <Directory /srv/www/test01>
       Order allow,deny
       Allow from all

   WSGIDaemonProcess test01.djangoserver processes=2 threads=15 display-name=%{GROUP}
   WSGIProcessGroup test01.djangoserver

   WSGIScriptAlias / /srv/www/test01/apache/django.wsgi


root@ubuntu1204-vm4:/srv/www# a2ensite test01
Enabling site test01.
To activate the new configuration, you need to run:
 service apache2 reload
root@ubuntu1204-vm4:/srv/www# /etc/init.d/apache2 restart

# ls /etc/apache2/sites-enabled/
test01  wsgi

please note that your client needs to map test01.djangoserver to IP address.
So it would be easy to configure /etc/hosts file on the client.
# cat /etc/hosts test01.djangoserver

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.