【问题标题】:uwsgi + django + nginx: Python application not loadinguwsgi + django + nginx:Python 应用程序未加载
【发布时间】:2017-08-11 17:50:43
【问题描述】:

根据一堆教程,我编写了我的第一个 django 应用程序,然后决定将它部署在 linode 服务器上。关注their tutorial,我只到此为止。我能说的最好的,是基于早期版本的 Ubunto,我尝试了其他一些东西,包括 uwsgi 快速入门教程。

我已经走得够远了,命令“python manage.py runserver”将为我的网站提供服务,并希望继续使用 uwsgi 来做同样的事情。

似乎缺少一些环境变量。当我尝试从命令行启动 uwsgi 时:

uwsgi --http :8000 --module dynamicefl.wsgi

我得到以下信息:

*** Starting uWSGI 2.0.15 (64bit) on [Fri Aug 11 19:37:04 2017] ***
compiled with version: 6.3.0 20170406 on 10 August 2017 23:41:13
os: Linux-4.9.36-x86_64-linode85 #1 SMP Thu Jul 6 15:31:23 UTC 2017
nodename: roosevelt
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/django/worksheets/dynamic-efl
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3941
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 5998)
uwsgi socket 0 bound to TCP address 127.0.0.1:43637 (port auto-assigned) fd 3
Python version: 2.7.13 (default, Jan 19 2017, 14:48:08)  [GCC 6.3.0 20170118]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x562bdad6fda0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
  File "./dynamicefl/wsgi.py", line 12, in <module>
    from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 5997, cores: 1)

很多教程都强调将虚拟环境的路径放在 .ini 文件中,我确实做到了(用 'env' 仔细检查我的虚拟环境是否正确。)这是我的 .ini 文件合作

[uwsgi]
home = /home/django/Env/worksheets
chdir = /home/django/worksheets/dynamic-efl/dynamicefl
module = dynamicefl.wsgi::application

uid = www-data
gid = www-data
socket = localhost:9191
chmod-socket = 644
chown-socket = www-data

processes = 4
threads = 2
logto = /var/log/uwsgi.log

我已经尝试过更改 chdir 命令,因为我不确定它应该指向的确切位置,但无论它指向哪里都会导致 uwsgi.log 中出现类似的行:

 -- no python application found, check your startup logs for errors ---

(有趣的事实:我一直无法找到对 uwsgi 启动日志的引用)

如果我在网络浏览器中访问该站点,我会收到“内部服务器错误”消息。

我不认为 nginx 有任何进展,但如果有帮助,我也可以包含 .conf 文件和错误日志。

我知道有类似问题的日志,但我查看过它们并没有帮助我。 (这并不是说它们不包含答案。)

【问题讨论】:

  • 我非常怀疑这与 Ubuntu 版本或环境变量有关。你安装了Django吗?如何以及在哪里?
  • 我确实从 virutalenv 的命令行安装了 Django。我的意思是在帖子中包含(将添加它)'python manage.py runserver 0.0.0.0:8000' 为我的网站提供服务。
  • 关于 Ubuntu 版本的一点是,linode 文档提到了新贵,显然 Ubuntu 16 使用 systemd。 (不知道我在说什么。)

标签: python django nginx uwsgi


【解决方案1】:

django docs 帮助了我。事实证明,我对模块的引用显然是错误的。在对模块的引用中,我的冒号太多了。更正后的 .ini 内容如下:

module = dynamicefl.wsgi:application

解决问题的方法是解决这个问题,直到我可以完全从 uwsgi 为网站提供服务,这样我就可以停止重新启动服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-28
    • 1970-01-01
    • 2017-08-21
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    相关资源
    最近更新 更多