日期:2014-05-16 浏览次数:20785 次
sudo apt-get update sudo apt-get upgrade
sudo apt-get install apache2 libapache2-mod-wsgi
sudo apt-get install python-setuptools sudo apt-get install python-pip
sudo pip install django
sudo mkdir /srv/www
sudo nano /etc/hosts
127.0.0.1 djangoserver 127.0.0.1 wsgi.djangoserver 127.0.0.1 hello.djangoserver
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]
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
cd /srv/www sudo django-admin.py startproject hello
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()
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