1、更新服务
安装Apache和mod_wsgi
安装工具setuptools 和pip
安装Django
创建站点目录
2、添加host进行测试
3、测试WSGI是否正常工作
添加以下内容:
创建一个新的apache站点
添加以下内容:
激活站点
http://wsgi.djangoserver
效果如下:
[img]http://dl.iteye.com/upload/attachment/604769/29428b71-e52c-349c-a042-ce22289a1b51.jpg[/img]
4、测试Django是否正常工作
创建Django工程
配置Django的wsgi文件
添加以下内容:
创建一个新的apache站点
添加以下内容:
激活站点
http://hello.djangoserver
效果如下:
[img]http://dl.iteye.com/upload/attachment/604765/eef44607-157c-378b-a7aa-4a3b4b3b43b1.jpg[/img]
原文地址:[url]http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/[/url]
sudo apt-get update
sudo apt-get upgrade
安装Apache和mod_wsgi
sudo apt-get install apache2 libapache2-mod-wsgi
安装工具setuptools 和pip
sudo apt-get install python-setuptools
sudo apt-get install python-pip
安装Django
sudo pip install django
创建站点目录
sudo mkdir /srv/www
2、添加host进行测试
sudo nano /etc/hosts
127.0.0.1 djangoserver
127.0.0.1 wsgi.djangoserver
127.0.0.1 hello.djangoserver
3、测试WSGI是否正常工作
sudo mkdir /srv/www/wsgi
sudo nano /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]
创建一个新的apache站点
sudo nano /etc/apache2/sites-available/wsgi
添加以下内容:
<VirtualHost *:80>
ServerName wsgi.djangoserver
DocumentRoot /srv/www/wsgi
<Directory /srv/www/wsgi>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /srv/www/wsgi/app.wsgi
</VirtualHost>
激活站点
sudo a2ensite wsgi
sudo /etc/init.d/apache2 reload
http://wsgi.djangoserver
效果如下:
[img]http://dl.iteye.com/upload/attachment/604769/29428b71-e52c-349c-a042-ce22289a1b51.jpg[/img]
4、测试Django是否正常工作
创建Django工程
cd /srv/www
sudo django-admin.py startproject hello
配置Django的wsgi文件
sudo mkdir /srv/www/hello/apache
sudo nano /srv/www/hello/apache/django.wsgi
添加以下内容:
import os
import sys
path = '/srv/www'
if path not in sys.path:
sys.path.insert(0, '/srv/www')
os.environ['DJANGO_SETTINGS_MODULE'] = 'hello.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
创建一个新的apache站点
sudo nano /etc/apache2/sites-available/hello
添加以下内容:
<VirtualHost *:80>
ServerName hello.djangoserver
DocumentRoot /srv/www/hello
<Directory /srv/www/hello>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess hello.djangoserver processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup hello.djangoserver
WSGIScriptAlias / /srv/www/hello/apache/django.wsgi
</VirtualHost>
激活站点
sudo a2ensite hello
sudo /etc/init.d/apache2 reload
http://hello.djangoserver
效果如下:
[img]http://dl.iteye.com/upload/attachment/604765/eef44607-157c-378b-a7aa-4a3b4b3b43b1.jpg[/img]
原文地址:[url]http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/[/url]