Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django+uWsgi+Nginx没有数据库数据,加上502页面更改错误_Python_Django_Nginx_Uwsgi - Fatal编程技术网

Python Django+uWsgi+Nginx没有数据库数据,加上502页面更改错误

Python Django+uWsgi+Nginx没有数据库数据,加上502页面更改错误,python,django,nginx,uwsgi,Python,Django,Nginx,Uwsgi,我试图让我的生产门户网站用Django编写,但是我遇到了一些问题。该页面将解析为登录页面,身份验证将起作用并将您带到第一个页面。然而,没有任何数据库数据将在那里,而且,如果我尝试切换页面,它将给我一个502错误 当我使用Django web服务器时,一切都正常工作。我相信这只是uWsgi设置的问题。这是我第一次使用django将服务器发布到生产环境中,因此我对自己的知识缺乏表示歉意 This is the error that triggers inside the log file upon

我试图让我的生产门户网站用Django编写,但是我遇到了一些问题。该页面将解析为登录页面,身份验证将起作用并将您带到第一个页面。然而,没有任何数据库数据将在那里,而且,如果我尝试切换页面,它将给我一个502错误

当我使用Django web服务器时,一切都正常工作。我相信这只是uWsgi设置的问题。这是我第一次使用django将服务器发布到生产环境中,因此我对自己的知识缺乏表示歉意

This is the error that triggers inside the log file upon switching pages
2014/10/22 17:19:03 [error] 21424#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 172.17.1.16, ser$
我读到这是因为需要设置uWsgi文件:

设置为:

我的项目/应用程序结构是

uWsgi配置:

Nginx配置:

my settings.py文件


我也有类似的问题。django运行的服务器一切正常,但在uwsgi中,我遇到了一个数据库访问错误。我的解决方案是确保pythonpath配置正确。 确保它已配置

尝试将其更改为硬编码链接,而不是:

pythonpath=%base/%projectname


尝试使用UNIX套接字,TCP端口可能会有问题。
plugin = Python
/var/www/dashboard/holon   # this is the project roon where I can run manage.py test server and everything will work.

/var/www/dashboard/holon/holon  #this is the project settings directory

/var/www/dashboard/holon/portal/ #this is the app directory

/var/www/dashboard/conf #this is where the Nginx and uWsgi config files live
[uwsgi]
# variables
projectname = holon
projectdomain = enki.co
base = /var/www/dashboard

# config
plugin = python
master = true
protocol = uwsgi
env = DJANGO_SETTINGS_MODULE=%(projectname).settings
pythonpath = %(base)/%(projectname)
module = %(projectname).wsgi
socket = 127.0.0.1:8001
logto = %(base)/logs/uwsgi.log
#below line runs it as a daemon in background
daemonize = /var/log/uwsgi/holon_dashboard.log
server {
    listen 80;
    server_name dashboard.enki.co;
    root /var/www/dashboard/holon;
    access_log /var/www/dashboard/logs/access.log;
    error_log /var/www/dashboard/logs/error.log;

    location /static/ { # STATIC_URL
        alias /var/www/dashboard/holon/portal/static/; # STATIC_ROOT
        expires 30d;
    }

    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:8001;
    }
}
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import ldap
from django_auth_ldap.config import *
import logging


BASE_DIR = os.path.dirname(os.path.dirname(__file__))

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'holon.backend.ActiveDirectoryBackend',
)

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ''

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

TEMPLATE_DEBUG = False

ALLOWED_HOSTS = [
         '127.0.0.1',
         '.enki.co',
         '172.19.32.220']


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'portal',
    'django_auth_ldap',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'holon.urls'

WSGI_APPLICATION = 'holon.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'metering',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '5433',
    },
    'OPTIONS': {
    'threaded': True,
    'use_returning_into': True,
    },
}

SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_PATH = os.path.join(SETTINGS_DIR, os.pardir)
PROJECT_PATH = os.path.abspath(PROJECT_PATH)
TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'templates')

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    TEMPLATE_PATH,
)


LOGIN_URL = '/login/'
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': '/tmp/debug.log',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },

    },
}

STATIC_URL = '/static/'