【问题标题】:Internal Server Error with Django and uWSGIDjango 和 uWSGI 的内部服务器错误
【发布时间】:2013-07-07 12:01:13
【问题描述】:

我正在尝试按照本指南中的步骤操作:http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

在进入 nginx 部分之前,我正在尝试确保 uWSGI 正常工作

我的文件夹结构是 srv/www/domain/projectdatabank/

项目数据库文件夹包含我的 manage.py 文件

我的 wsgi.py 文件如下所示:

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

您需要查看我的 settings.py 吗?

当我将自己指向浏览器时出现以下错误:

-- no python application found, check your startup logs for errors --- [pid: 10165|app: -1|req: -1/1] 66.56.35.151 () {38 vars in 681 bytes} [Tue Jul 9 18:19:46 2013] GET /admin/ => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0) --- no python application found, check your startup logs for errors --- [pid: 10165|app: -1|req: -1/2] 66.56.35.151 () {36 vars in 638 bytes} [Tue Jul 9 18:19:49 2013] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)

现在当我检查我的 uWGI 日志时,它和上面的一样。

【问题讨论】:

    标签: django uwsgi


    【解决方案1】:

    查看我关于在 uwsgi http://blog.johannesklug.de/2012/11/27/deploying-django-behind-nginx-with-uwsgi-and-virtualenv/ 后面部署 Django 的博文。我创建了一个 ini-File 来设置 uwsgi,它指向可以使用参数 module=project.wsgi:application 调用的应用程序。

    整个文件的内容如下:

    (env)[project@host ~]$ cat uwsgi.ini 
    [uwsgi]
    # path to where you put your project code
    chdir=/home/project/project
     
    # python path to the wsgi module, check if you have one
    module=project.wsgi:application
     
    # this switch tells uwsgi to spawn a master process,
    # that will dynamically spawn new child processes for
    # server requests
    master=True
    # uwsgi stores the pid of your master process here
    pidfile=/home/project/master.pid
    vacuum=True
    # path to your virtual environment
    home=/home/project/env/
    # path to log file
    daemonize=/home/project/log
    # this is where you need to point nginx to,
    # if you chose to put this in project home make
    # sure the home dir is readable and executable by
    # nginx
    socket=/tmp/uwsgi.sock
     
    ### SEE UPDATE NOTICE FOR THIS ONE
    env = DJANGO_SETTINGS_MODULE=project.settings
    

    请注意,我使用的是 virtualenv。

    你也可能错过了这些行

    import os
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
    

    在你的wsgi.py

    【讨论】:

      【解决方案2】:

      uwsgi.ini

      确保您已设置正确的module

      [uwsgi]
      module = yourapp.wsgi:application
      ...
      

      【讨论】:

        【解决方案3】:

        我收到此错误是因为我正在运行的站点的 /etc/uwsgi/vassals/ ini 文件将单词“module”拼写为“modeule”。如果您看到 htis 错误,请仔细检查该文件。

        【讨论】:

          【解决方案4】:

          检查您是否从 Djano 应用程序中删除了任何 init.py 文件。由于 django 使用它们来知道哪些文件夹是应用程序,所以它们很重要。

          【讨论】:

            【解决方案5】:

            对于调试相同错误的其他人,还有另一种可能性:您的uwsgi.py 引发了异常。要对此进行测试,请直接使用 python manage.py shell 在您的应用中打开一个 django shell,然后导入您的 uwsgi.py(使用与您的 uwsgi.ini 中相同的路径)。

            【讨论】:

            • @AlexVanLiew 添加更多信息来调试问题是完全合适的。现有答案仅解决一种可能的错误(路径)。你是谁来判断人们应该为 SO 做出什么贡献?
            • 好吧,我刚刚在我的日志中使用完全相同的错误消息调试了这个确切的问题,这是因为在 uwsgi.py 中引发了异常。所以,你的直觉是错误的。
            • @AlexVanLiew - SO 与论坛不同。在这里answer old questions 并不合适。事实上,有一个necromancer 徽章。如果有任何问题的信息,无论是否回答,可能会为未来的访问者增加价值,应该添加它。这就是问答网站的全部目的。
            • 另一个可能导致此错误消息的问题是数据库无法正确连接。我只是偶然发现了这一点,只是我忘记添加密码了。棘手的部分是manage.py dbshell 并不一定会揭示这一点,因为它使用来自 .pgpass (PostgreSQL) 的密码
            • 另一个投票支持这个答案的极端有用性。我的错误是我的日志配置,甚至不是 uwsgi,@AlexVanLiew,我得到了同样的确切消息。我没想到只打开一个shell(甚至不必导入uwsgi)。 UWSGI 是可怕的错误并且完全不透明,因此需要任何有助于调试 UWSGI 引发的错误消息的东西。
            【解决方案6】:

            我已经解决了

            在我原来的命令行中没有包含运行 uWSGI 的 wsgi.py 文件的完整路径

            uwsgi --http :8000 --chdir /srv/www/databankinfo.com/projectdatabank/ --wsgi-file wsgi.py
            

            到这里

            uwsgi --http :8000 --chdir /srv/www/databankinfo.com/projectdatabank/ --wsgi-file full/path/wsgi.py
            

            成功了

            【讨论】:

            • 我发现自己想知道为什么会发生这种情况,因为没有人问这可能很明显,但对我来说不是,为什么这能解决您的问题?
            猜你喜欢
            • 2015-07-21
            • 1970-01-01
            • 2019-02-05
            • 2015-09-22
            • 2014-07-31
            • 2017-08-31
            • 2023-03-25
            • 2011-03-18
            • 1970-01-01
            相关资源
            最近更新 更多