uWSGI + Django + Nginx - 运行时错误

问题描述 投票:0回答:1

第一篇关于Stackoverflow +的帖子绝对需要:

我正在尝试建立一个Ubuntu 16.04服务器来托管我的Django应用程序,但是我遇到了一个与uWSGI的奇怪错误;每当我跑:

uwsgi --socket test.sock --module api.wsgi:app --chmod-socket=66

我明白了:

Python version: 3.5.2 (default, Nov 23 2017, 16:37:01)  [GCC 5.4.0 20160609]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x8025d0
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 890, in _find_spec
AttributeError: 'ConfigurationImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./api/wsgi.py", line 14, in <module>
    from configurations.wsgi import get_wsgi_application
  File "/usr/local/lib/python3.5/dist-packages/configurations/wsgi.py", line 14, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 22, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 110, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 954, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 892, in _find_spec
  File "<frozen importlib._bootstrap>", line 873, in _find_spec_legacy
  File "/usr/local/lib/python3.5/dist-packages/configurations/importer.py", line 132, in find_module
    imp.find_module(module, path))
  File "/usr/lib/python3.5/imp.py", line 270, in find_module
    "not {}".format(type(name)))
RuntimeError: 'list' must be None or a list, not <class 'str'>
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** uWSGI is running in multiple interpreter mode ***

这是我的wsgi.py文件:

import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
os.environ.setdefault('DJANGO_CONFIGURATION', 'Production')

from configurations.wsgi import get_wsgi_application

application = get_wsgi_application()

这是我的uwsgi.ini文件:

[uwsgi]

project = mysite
base = /home/ubuntu

chdir = %(base)/%(project)
home = %(base)/%(project)/env
module = %(project).wsgi:application

vacuum = true


# process-related settings
master = true
processes = 8
socket = /run/uwsgi/mysite.sock
chmod-socket = 666
max-requests = 50000

logto = /var/log/uwsgi/app/logs.log

为了更好的衡量,这是我的nginx文件:

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/ubuntu/mysite/test.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name mysite.io; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /home/ubuntu/mysite/static;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/ubuntu/mysite/media; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     uwsgi_params; # the uwsgi_params file you installed
    }
}

我真的不知道造成这种情况的原因。我现在尝试使用Gunicorn,它显示了同样的错误。非常感谢任何帮助! :)

django ubuntu nginx uwsgi wsgi
1个回答
0
投票

在uwsgi.py中你有:

application = get_wsgi_application()

并且您正在使用参数运行uwsgi:

uwsgi --socket test.sock --module api.wsgi:app --chmod-socket=66

尝试用api.wsgi:app替换api.wsgi:application并查看它是否运行。

© www.soinside.com 2019 - 2024. All rights reserved.