我已经设置了一个数字海洋一键式应用程序(安装了django nginx gunicorn并设置了https://www.digitalocean.com/community/tutorials/how-to-use-the-django-one-click-install-image).默认值对我有效,但在我尝试通过服务gunicorn重新启动应用代码更改后,我收到了502错误,其中包含以下nginx错误日志行:
connect() to unix:/home/django/gunicorn.socket failed (111: Connection refused) while connecting to upstream, client: 178.136.215.70, server: _, request: "GET / HTTP/1.1",upstream: "http://unix:/home/django/gunicorn.socket:/"..
我已经研究了类似的问题并发现它经常是由ALLOWED_HOSTS中的错误引起的,一切都在那里,但我也尝试用单个’*’替换’ip’或’www.address.com’并得到不同的错误:
recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 178.136.215.70, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "192.241.176.184"
编辑:好的,现在它更容易,gunicorn错误日志告诉我们rest_framework存在导入错误,但它已经安装并且它出现在已安装的应用程序中(并拼写正确),我检查了几千次所以这是真正的错误这一切?
File "/usr/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/usr/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/lib/python2.7/dist-packages/gevent/builtins.py", line 93, in __import__
result = _import(*args, **kwargs)
File "/home/django/django_project/blog/models.py", line 5, in <module>
from rest_framework import serializers
File "/usr/lib/python2.7/dist-packages/gevent/builtins.py", line 93, in __import__
result = _import(*args, **kwargs)
ImportError: No module named rest_framework
(目前唯一的问题)EDIT2:我重新安装了app文件夹,再次检查了一切.现在它告诉ImportError:没有名为django_ajax的模块. Python 2.7,Django 1.8,Gunicorn 19.4.5(https://github.com/yceruto/django-ajax)尽管一切似乎都是正确的
编辑:pip冻结的Résponse:
Django==1.8
django-filter==1.0.1
-e git://github.com/yceruto/django-ajax@9c122e68f8e7ca92333a1533fa464ee6da0f65c5#egg=djangoajax
djangorestframework==3.5.3
gunicorn==19.6.0
Markdown==2.6.7
netifaces==0.10.5
pkg-resources==0.0.0
psycopg2==2.6.2
解决方法:
当您执行Sudo时,将为root用户安装该程序包并将其全局安装.检查此link以了解sudo pip的工作原理.现在您的软件包已全局安装,它正在运行.
我仍然怀疑它使用的是哪种Python.在错误消息中,它试图访问全局dist-packages目录下的包.不是来自虚拟环境.所以,你的gunicorn发送链接到全局安装的Python而不是虚拟环境.
理想情况下,发生的错误应该指向/path/to/virtual_env/virtual_env/lib/python2.7/dist-packages下的dist-packages,因为这是python&想要使用的库环境.这似乎是个问题.
如果是这种情况,您可以执行以下操作
DJANGODIR = /路径/到/ Django的项目/
DJANGO_SETTINGS_MODULE = Django的project.settings
激活虚拟环境
cd $DJANGODIR
source / path / to / virtualenv / bin / activate
导出DJANGO_SETTINGS_MODULE = $DJANGO_SETTINGS_MODULE
export PYTHONPATH = $DJANGODIR:$PYTHONPATH
我认为这应该可以解决所有问题…请尝试一下,如果我错过了什么,请知道