1

我正在尝试使用 django 站点中的教程在现有的 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 failure Files inside directive inside directory(如示例中所述)给我同样的失败

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

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

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

4

1 回答 1

0

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

启用模块

你可以我的项目结构这个问题。请参阅此问题以了解项目结构

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

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()

我想这会对你有所帮助。

于 2015-11-26T04:37:10.427 回答