超简单系列:ubuntu 13.04 安装 apache2.2+mod_wsgi+Django

1,Ubuntu更新系统

sudo apt-get update
sudo apt-get upgrade

2,安装apache,mod_wsgi,Django

sudo apt-get install apache2 libapache2-mod-wsgi  python-django

更多Ubuntu系统内置安装包请搜索:Ubuntu Packages Search

3,配置Django环境

sudo mkdir  /opt/wwwroot

cd /opt/wwwroot
sudo django-admin startproject hello

    创建wsgi文件

sudo mkdir /opt/wwwroot/hello/apache
sudo vi /opt/wwwroot/hello/apache/django.wsgi

    文件django.wsgi贴入下面内容

django.wsgi内容
import os
import sys
sys.path.append('/opt/wwwroot')
sys.path.append('/opt/wwwroot/hello')
path = '/opt/wwwroot'

if path not in sys.path:
    sys.path.insert(0, '/opt/wwwroot')

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

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

4,创建一个新的apache站点

sudo vi /etc/apache2/sites-available/hello
hello内容
<VirtualHost *:80>

    ServerName hello.com
    DocumentRoot /opt/wwwroot/hello

    <Directory /opt/wwwroot/hello>
        Order allow,deny
        Allow from all
    </Directory>
    Alias /robots.txt /opt/wwwroot/hello/robots.txt
    Alias /favicon.ico /opt/wwwroot/hello/favicon.ico
    Alias /images /opt/wwwroot/hello/images
    Alias /static /opt/wwwroot/hello/static

    WSGIDaemonProcess hello.com processes=2 threads=15 display-name=%{GROUP}
    WSGIProcessGroup hello.com
    WSGIScriptAlias / /opt/wwwroot/hello/apache/django.wsgi

 </VirtualHost>

   激活hello站点

sudo a2ensite hello
sudo service apache2 reload

5,设置完毕打开浏览器进入输入ip地址,就可以看到Django欢迎界面了。

6.  如果发现文件访问不了,权限的问题

sudo chown -R (group).(user)  (your project dir)

 

Django官网部署链接:https://docs.djangoproject.com/en/1.2/howto/deployment/

posted @ 2014-04-10 08:50  smallcoderhujin  阅读(1233)  评论(0编辑  收藏  举报