无法使用apache mod WSGI在ubuntu上部署Django

时间:2014-03-08 15:18:49

标签: python django apache ubuntu

我正在使用ubuntu 12.04而且我做了以下事情:

  

sudo apt-get install python-mysql

     

sudo python setup.py install(安装Django 1.6.2)

     

sudo apt-get install mysql-server -...

     

sudo apt-get install apache2

     

sudo apt-get install libapache2-mod-wsgi

以下是我的配置文件:

/home/firstweb.wsgi:

import os
import sys
sys.path = ['/var/www/firstweb'] + sys.path
os.environ['DJANGO_SETTINGS_MODULE'] = 'firstweb.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

/etc/apache/sites-availables/firstweb.conf:

<VirtualHost *:80>
WSGIScriptAlias / /home/adel/firstweb.wsgi
ServerName firstweb.com
Alias /static /var/www/firstweb/static/

<Directory /var/www/firstweb/>
order allow,deny
Allow from all
</Directory>
</VirtualHost>
然后我做了:

  1. a2ensite firstweb.conf
  2. cd /var/www/
  3. django-admin.py startproject firstweb
  4. apachectl restart
  5. vi /etc/hosts
  6. 并添加以下内容(192.168.0.123是我的wlan ip)

    192.168.0.123 firstweb.com

    我使用mysql并创建数据库并更改settings.py并且syncdb正常工作

    但是当我在浏览器中输入www.firstweb.com时,会出现Apache的默认页面(它有效......)

    并且Django默认页面没有出现!!

    我的配置有什么问题?

    谢谢。

2 个答案:

答案 0 :(得分:1)

您的虚拟服务器没有在www.firstweb.com上收听,只能在firstweb.com上收听。您应该为www版本添加ServerAlias指令。

答案 1 :(得分:0)

您的WSGIScriptAlisa指令引用的路径不在您指定给Directory指令的任何目录中,指示允许Apache从哪里提供文件/脚本。此外,Apache用户通常无法访问用户主目录下的文件。这两个问题都会导致不同的Forbidden HTTP响应。因此,即使您解决了ServerName / ServerAlias和主机问题,您也可能会遇到这些问题。请确保您阅读Django网站上的官方mod_wsgi部署文档。