我试图让用Django编写的生产Web门户工作,但是我遇到了一些问题。该页面将解析为登录页面,身份验证将起作用并带您进入第一页。但是,没有数据库数据存在,此外,如果我尝试切换页面,它将给我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文件:
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 config:
[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
Nginx配置:
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;
}
}
我的settings.py文件
# 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/'
答案 0 :(得分:0)
我有类似的问题。一切都运行良好的django运行服务器,但在uwsgi我有一个数据库访问错误。我的解决方案是确保正确配置pythonpath。 确保它已配置。
尝试将其更改为硬编码链接,而不是:
pythonpath =%(base)/%(projectname)