【问题标题】:Setting up django and apache using the tutorial isn't working使用教程设置 django 和 apache 不起作用
【发布时间】:2014-07-03 22:47:30
【问题描述】:

我正在尝试使用 django 站点 here 中的教程使用现有的 django 项目设置 apache。我的操作系统是 Ubuntu,一切都安装好了(django apache2 libapache2-mod-wsgi)

我的配置文件

WSGIPythonPath /home/avlahop/development/django/rhombus2/rhombus/

<VirtualHost *:80>
    ServerName myrhobmus.com
    ServerAlias www.myrhombus.com
    WSGIScriptAlias / /home/avlahop/development/django/rhombus2/rhombus/rhombus/wsgi.py 
</VirtualHost>

创建 conf 文件后,我运行 a2ensite Ubuntu 命令来启用该站点。

将 WSGIPythonPath 放入 VirtualHost 会导致 apache configtest 失败 目录内指令中的文件(如示例中所述)给了我同样的失败

如果我访问 www.myrhombus.com,我会收到一条 Google chrome 找不到指定地址的消息。

我做错了什么? Internet 上的每个教程都使用旧的 file.wsgi,而现在 Django 会为您创建它,但它是一个带有 .py 扩展名的 python 文件。如何使用 apache 为我的 django 服务?如果我想在我自己的服务器上进行生产,你会把 django 代码放在哪里,你会把模板文件放在哪里?

编辑:我只得到 / 页面的索引。就权限而言,我与 mysites 位置有什么关系吗?你能给我一个 django 站点 apache conf 文件的工作示例吗?

【问题讨论】:

  • 您看到的确切错误是什么?
  • 在这种情况下?重新启动 django 或尝试访问我的域时。我通过 /etc/hosts 解决了域访问我的放置记录,例如 127.0.0.1 www.myrhombus.com 但现在我得到的是一个列表,其中包含目录包含的假设文件(但不显示任何文件),索引为/ 标题和最后修改的名称 大小描述列
  • 您说您遇到了 Apache 配置测试失败。它到底说了什么?
  • 如果我在 VirtualHost 中添加 WSGIPythonPath,我得到的错误如下: 配置测试的输出是:AH00526:/etc/apache2/sites-enabled/rhombus.conf 第 5 行的语法错误:WSGIPythonPath 部分中不能发生操作“configtest”失败。文件似乎是固定的。可能是我的笔误。但我只是得到 / 页面的索引而不是我的 django 页面
  • @Apostolos,如果您解决并成功部署您的项目。希望有所帮助。stackoverflow.com/questions/33890277/…我也面临类似的问题。

标签: python django apache django-deployment


【解决方案1】:

我使用 Django 1.8 并成功部署了我的项目 Apache 服务器。我像你一样遵循基本概念,并很早就启用了 Apache 这个模块。

enable module

你可以我的项目结构这个问题。Refer this question to understand project structure

-------------这是我的虚拟主机文件-------------------------- -------

WSGIPythonPath /home/umayanga/Desktop/view_site/serialKey_gen_site:/home/umayanga/Desktop/view_site/serialKey_gen_site/myvenv/lib/python3.4/site$

<VirtualHost *:80>
    ServerAdmin admin@key.com
    ServerName key.com
    ServerAlias www.key.com

    Alias /templates/ /home/umayanga/Desktop/view_site/serialKey_gen_site/templates/
    Alias /static/ /home/umayanga/Desktop/view_site/serialKey_gen_site/static/


    <Directory "/home/umayanga/Desktop/view_site/serialKey_gen_site/static">
           Require all granted
    </Directory>

    <Directory "/home/umayanga/Desktop/view_site/serialKey_gen_site/templates">
           Require all granted
    </Directory>

    WSGIScriptAlias / /home/umayanga/Desktop/view_site/serialKey_gen_site/mysite/wsgi.py

    <Directory "/home/umayanga/Desktop/view_site/serialKey_gen_site/mysite">
        Options Indexes FollowSymLinks
        AllowOverride all
        Require all granted
        <Files wsgi.py>
               Require all granted
        </Files>
    </Directory>

</VirtualHost>

-----------------wsgi.py--------------- ------------

"""
WSGI config for mysite project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application



os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

application = get_wsgi_application()

我想这会对你有所帮助。

【讨论】:

    猜你喜欢
    • 2013-04-13
    • 2014-04-10
    • 2013-12-25
    • 2016-05-10
    • 2015-08-03
    • 2010-09-07
    • 2013-05-03
    • 2021-12-10
    • 2012-04-21
    相关资源
    最近更新 更多