【问题标题】:unable to deploy Django on ubuntu with apache mod WSGI无法使用 apache mod WSGI 在 ubuntu 上部署 Django
【发布时间】:2014-04-11 20:10:38
【问题描述】:

我使用的是 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

并添加以下内容(192.168.0.123 是我的 wlan ip)

192.168.0.123 firstweb.com

我使用 mysql 并创建了一个数据库并更改了 settings.pysyncdb 工作正常

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

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

我的配置有什么问题?

谢谢。

【问题讨论】:

    标签: python django apache ubuntu


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您的虚拟服务器未在 www.firstweb.com 上侦听,而仅在 firstweb.com 上侦听。您应该为 www 版本添加一个 ServerAlias 指令。

      【讨论】:

      • 将此添加到您的 apache 配置文件中:ServerAlias www.firstweb.com
      • 谢谢knapo,但是什么配置文件?我的 /etc/apache2 中有 httpd.conf 和 http.conf ,它们都是空白的。还有其他配置文件吗?我的 apache2 配置文件在哪里??
      • 将其添加到上面显示的 conf 文件中,在您指定 ServerName 的位置旁边。
      • 你好丹尼尔我做到了,问题仍然存在!
      猜你喜欢
      • 2014-11-24
      • 2014-09-09
      • 2022-12-30
      • 1970-01-01
      • 1970-01-01
      • 2014-12-02
      • 2014-07-15
      • 2014-05-21
      • 1970-01-01
      相关资源
      最近更新 更多