【问题标题】:Django website on Apache with wsgi failingApache 上的 Django 网站,wsgi 失败
【发布时间】:2016-10-12 05:44:27
【问题描述】:

所以我要吃午饭我的第一个 django 网站,我目前有一个已配置为托管 php 网站的服务器,我决定测试一个简单的空项目以熟悉该过程

所以这个服务器中的python版本有点旧(2.6)所以我无法安装最新版本的django,我安装了1.6,因为它只是一个不重要的测试(当我的网站是时我会升级python版本)准备吃午饭了)

所以我安装了 django 并创建了一个名为 testing in this dire 的新项目

/home/sdfds34fre/public_html/

你可以看到使用这个域

http://novadmin20.com

在阅读了有关 django 的文档(不幸的是,他们已经删除了 1.6 的文档,我不得不使用 1.9)和 wsgi 之后,我已经像这样更新了我的 httpd.conf

<VirtualHost 111.111.111.111:80>
    ServerName 111.111.111.111
    DocumentRoot /usr/local/apache/htdocs
    ServerAdmin somemeail@gmail.com
    <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
    </IfModule>

    <Directory /home/sdfds34fre/public_html/testing/testing>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>


    WSGIDaemonProcess testing python-path=/home/sdfds34fre/public_html/testing:/usr/lib64/python2.6/site-packages/
    WSGIProcessGroup testing
    WSGIScriptAlias / /home/sdfds34fre/public_html/testing/testing/wsgi.py


</VirtualHost>

但即使在我去时重新启动httpd服务之后

http://novadmin20.com/testing/

我看到的只是目录列表,我错过了什么吗?

这是我的 wsgi.py 文件

"""
WSGI config for testing 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.6/howto/deployment/wsgi/
"""

import os
import sys

sys.path.append(os.path.dirname(os.path.dirname(__file__)))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testing.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

【问题讨论】:

  • 您使用的是什么 Linux 发行版,您有 root 访问权限吗?如果您使用的是 CentOS 6(Python 2.6),那么安装更新的 Python 替代版本并针对它编译 mod_wsgi 会相当容易。我有分步说明,如果可以,请告诉我。
  • @FlipperPA thanx 这个服务器是 centos 6,但我已经为这个网站订购了一个带有 centos 7 的新服务器......我不确定 centos 7 会附带什么版本的 python
  • CentOS 7 附带 Python 2.7.5 作为系统 Python。我建议不要在系统上运行 Django;最好使用 virtualenv。祝你好运!

标签: python django apache centos mod-wsgi


【解决方案1】:

DocumentRoot 指令是您问题的主要根源。 (ref)

试试这个配置:

<VirtualHost 111.111.111.111*:80>
 ServerName novadmin20.com

 WSGIDaemonProcess testing python-path=/home/sdfds34fre/public_html/testing:/usr/lib64/python2.6/site-packages/
 WSGIScriptAlias / /home/sdfds34fre/public_html/testing/testing/wsgi.py

  <Directory /home/sdfds34fre/public_html/testing/testing>
     <Files wsgi.py>
      Order deny,allow
      Require all granted
      WSGIProcessGroup testing
    </Files>
   </Directory>

</VirtualHost>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2018-03-05
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多