Django和uWSGI 2皇帝模式出现内部服务器错误

7
我一直在尝试阅读与此问题相关的所有内容(并在此过程中学到了很多)。我找到的最接近的链接是这里这里。我的问题几乎完全相同,只是我专门在emperor模式下运行uwsgi。当我在不运行emperor模式的情况下运行uswsgi服务时,我的django网站运行得非常好。无论我如何更改配置,我总是会在我的/tmp/uwsgi.log文件中收到错误消息:"--- no python application found, check your startup logs for errors ---"。我在下面列出了我的配置和错误日志:
操作系统版本:Linux raspberrypi 3.6.11+ #538 armv6l GNU/Linux Django版本:1.6.5 uwsgi版本:2.0.5.1
虚拟环境:/var/www/testbed/env 项目位置:/var/www/testbed/project/auth 项目树:
./auth/
|-- __init__.py
|-- __init__.pyc
|-- requirements.txt
|-- settings.py
|-- settings.pyc
|-- urls.py
|-- urls.pyc
|-- wsgi.py
`-- wsgi.pyc

文件 wsgi.py:

"""
WSGI config for auth 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, sys, site

    sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
    sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
    sys.path.append('/usr/lib/python2.7')
    sys.path.append('/usr/lib/python2.7/dist-packages')

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

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

文件 /etc/uwsgi/emperor.ini:

[uwsgi]
master = true
emperor = /etc/uwsgi/vassals
logto = /tmp/uwsgi.log

文件路径 /etc/uwsgi/vessals/auth.ini:

[uwsgi]
#plugins = python
# Django-related settings
chdir           =/var/www/testbed/project/auth
module          = auth.wsgi:application

# the virtualenv (full path)
home            =/var/www/testbed/env
virtualenv      =/var/www/testbed/env

# process-related settings
enable-threads  = true
pythonpath      = /var/www/testbed/project/auth
#wsgi-file      = /var/www/testbed/project/auth/auth/wsgi.py
env             = DJANGO_SETTINGS_MODULE=auth.settings

mount = /testbed/auth/admin=/var/www/testbed/project/auth/auth/wsgi.py
manage-script-name = true
#route-run = log:SCRIPT_NAME=${SCRIPT_NAME}

# maximum number of worker processes
processes       = 1 #Simple rule is # of cores on machine
# the socket (use the full path to be safe
socket          = /var/www/testbed/project/auth/uwsgi.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 664
# clear environment on exit
vacuum          = true
logto           = /tmp/uwsgi.log

正在执行的命令如下所示:
/var/www/testbed/env/bin/uwsgi --ini /etc/uwsgi/emperor.ini --emperor /etc/uwsgi/vassals/ --http :8000  --plugin python --binary-pathusr/local/bin/uwsgi

错误文件 /tmp/uwsgi.log:

*** Starting uWSGI 2.0.5.1 (32bit) on [Tue Jun 10 19:06:12 2014] ***
compiled with version: 4.6.3 on 10 June 2014 01:41:52
os: Linux-3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013
nodename: raspberrypi
machine: armv6l
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your processes number limit is 3376
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 6
*** starting uWSGI Emperor ***
uwsgi socket 0 bound to TCP address 127.0.0.1:57524 (port auto-assigned) fd 5
Python version: 2.7.3 (default, Mar 18 2014, 05:13:23)  [GCC 4.6.3]
*** has_emperor mode detected (fd: 8) ***
[uWSGI] getting INI configuration from auth.ini
*** Starting uWSGI 2.0.5.1 (32bit) on [Tue Jun 10 19:06:12 2014] ***
compiled with version: 4.6.3 on 09 June 2014 23:07:00
os: Linux-3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013
nodename: raspberrypi
machine: armv6l
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your processes number limit is 3376
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 socket 0 bound to UNIX address /var/www/testbed/project/auth/uwsgi.sock fd 3
Python version: 2.7.3 (default, Mar 18 2014, 05:13:23)  [GCC 4.6.3]
Set PythonHome to /var/www/testbed/env
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1dca830
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 128512 bytes (125 KB) for 1 cores
*** Operational MODE: single process ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 23068)
spawned uWSGI worker 1 (pid: 23071, cores: 1)
spawned uWSGI http 1 (pid: 23072)
Python main interpreter initialized at 0x616918
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 128512 bytes (125 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/testbed/project/auth/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x616918 pid: 23070 (default app)
mounting /var/www/testbed/project/auth/auth/wsgi.py on /testbed/auth/admin
added /var/www/testbed/project/auth/ to pythonpath.
WSGI app 1 (mountpoint='/testbed/auth/admin') ready in 3 seconds on interpreter 0x9c6218 pid: 23070
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 23070)
Tue Jun 10 19:06:18 2014 - [emperor] vassal auth.ini has been spawned
spawned uWSGI worker 1 (pid: 23073, cores: 1)
Tue Jun 10 19:06:18 2014 - [emperor] vassal auth.ini is ready to accept requests
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/1] 192.168.1.6 () {38 vars in 742 bytes} [Tue Jun 10 19:07:11 2014] GET /testbed/auth/admin => generated 21 bytes in 1 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/2] 192.168.1.6 () {36 vars in 626 bytes} [Tue Jun 10 19:07:11 2014] GET /favicon.ico => generated 21 bytes in 1 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/3] 192.168.1.6 () {38 vars in 742 bytes} [Tue Jun 10 19:07:13 2014] GET /testbed/auth/admin => generated 21 bytes in 2 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/4] 192.168.1.6 () {36 vars in 626 bytes} [Tue Jun 10 19:07:13 2014] GET /favicon.ico => generated 21 bytes in 1 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

此时此刻,我已经是不折不扣的无助了。我浏览了大量的文献,但却不明白为何会一直出现“内部服务器错误”的提示。可能是我忽略了某个细节,所以我最终放下面子在这里寻求帮助。既然我已经走到了这一步,我真心觉得问题可能只是一个微不足道的小错误。如有任何帮助,将不胜感激。

1
我遇到了相同的错误。你解决了吗? - Mevin Babu
我之前也遇到了同样的问题,原因是没有安装Django。我在一个新的vagrant环境中工作,然后运行了"pip install django"命令,问题就解决了。 - ChrisC
如果问题仍未解决:我经常遇到权限问题,通过手动设置组和用户(在我的情况下为 --uid www-data --gid www-data),就像这个指南中所述的那样,问题得以解决:http://uwsgi.readthedocs.org/en/latest/tutorials/Django_and_nginx.html。 - MBrizzle
!!! 没有内部路由支持,请使用 pcre 支持重新构建 !!! - uwsgi 告诉你,问题出在哪里 - nnmware
它说它无法加载Python代码,您确定已正确寻址wsgi.py吗?将DEBUG设置为True并使用Django日志更新问题。 - shalbafzadeh
1个回答

0

我在使用usgi-emperor进行部署时遇到了这个问题,而问题是我没有在Django项目的配置文件中设置正确的ALLOWED_HOSTS。

在您的配置中,您应该有:

ALLOWED_HOSTS=[ "yourdomain.com", "other.domain.com" ]

或者这样做(由于安全问题不建议使用,风险自负):

ALLOWED_HOSTS=["*"]

允许任何主机

https://docs.djangoproject.com/en/1.8/ref/settings/#allowed-hosts


1
我建议为“复制/粘贴”读者添加一条注释,指出星号解决方案强烈不建议使用,除非您知道自己在做什么。 - alekosot

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接