Конечная точка транспорта не подключена - apache размещено django приложение - PullRequest
0 голосов
/ 27 апреля 2020

Я только что развернул свое первое приложение Django на своем веб-сервере apache и столкнулся с следующей проблемой:

Я настроил мое приложение django, чтобы вы могли входить с его учетными данными. Если я запускаю сервер через веб-сервер разработки (python manage.py runserver), он работает просто отлично.

Но если мой apache хостит приложение, он говорит:

Caught LDAPError while authenticating adaccount: SERVER_DOWN({'desc': "Can't contact LDAP server", 'errno': 107, 'info': 'Transport endpoint is not connected'},)

Я знаю, что это должно что-то с apache. Я пробовал 3 настройки KeepAlive On, MaxKeepAliveRequests и KeepAliveTimout, но безуспешно. Любая идея?

Вот мой Settings.py

import os
import ldap


os.environ.setdefault("DJANGO_SETTINGS_MODULE", __file__)
import django
#django.setup()

from django_auth_ldap.config import LDAPSearch

AUTH_LDAP_SERVER_URI = 'ldap://dnsOfLDAP:3268'
AUTH_LDAP_BIND_DN = "serviceaccount"
AUTH_LDAP_BIND_PASSWORD = "some***"
AUTH_LDAP_USER_SEARCH = LDAPSearch(
            "searchScope", ldap.SCOPE_SUBTREE, "sAMAccountName=%(user)s"
            )

AUTH_LDAP_USER_ATTR_MAP = {
            "username": "sAMAccountName",
                "first_name": "givenName",
                    "last_name": "sn",
                        "email": "UserPrincipalName",
}
from django_auth_ldap.config import ActiveDirectoryGroupType
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
            "searchScope", ldap.SCOPE_SUBTREE, "(objectCategory=Group)"
            )
AUTH_LDAP_GROUP_TYPE = ActiveDirectoryGroupType(name_attr="cn")
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
            #"is_active": "activeGroup",
            "is_staff": "staffGroup",
            }


AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_CACHE_GROUPS = True
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 1  # 1 hour cache

#ohne apache auth backend
AUTHENTICATION_BACKENDS = [
           'django_auth_ldap.backend.LDAPBackend',
           'django.contrib.auth.backends.ModelBackend',
           'django.contrib.auth.backends.RemoteUserBackend',
]

#mit apache auth backend
# AUTHENTICATION_BACKENDS = [
#     'django.contrib.auth.backends.RemoteUserBackend',
# ]



REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',
    )
}

# For production

# CSRF_COOKIE_SECURE = True
# SESSION_COOKIE_SECURE = True



# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
SECRET_KEY = 'superSecretKey'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'api',
    'iamapi',
    'rest_framework.authtoken',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.RemoteUserMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'databaseProject.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'databaseProject.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': 'databaseIP',
        'NAME': 'database',
        'USER': 'databaseuser',
        'PASSWORD': 'superSecretPassword',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/databaseProject/static/'

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {"console": {"class": "logging.StreamHandler"}},
    "loggers": {"django_auth_ldap": {"level": "DEBUG", "handlers": ["console"]}},
}

А вот мой apache файл конфигурации:

<VirtualHost *:80>

    ServerName «currentIP”
    #ServerAlias example.com
    #ServerAdmin webmaster@example.com

    DocumentRoot "/var/www/html"
    Include conf.modules.d/*.conf
    LoadModule wsgi_module /usr/local/lib64/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
    LoadModule auth_basic_module modules/mod_auth_basic.so
    LoadModule authz_user_module modules/mod_authz_user.so

    KeepAlive On
    MaxKeepAliveRequests 100
    KeepAliveTimeout 5

    Alias /static/ /var/www/databaseProject/static/

    <Directory /var/www/databaseProject/static>
    Require all granted
    </Directory>

    <Directory /var/www/html/databaseProject>
    Require all granted
    AuthBasicProvider wsgi
    WSGIPassAuthorization On
    AuthBasicProvider wsgi
    WSGIAuthUserScript /var/www/html/databaseProject/databaseProject/wsgi.py
    <Files wsgi.py>
    Require all granted
    </Files>
    </Directory>

    WSGIDaemonProcess “currentIP” processes=2 threads=15 display-name=%{GROUP} python-path=/var/www/html/databaseProject
    WSGIProcessGroup “currentIP”
    #WSGIPythonPath /var/www/html/databaseProject
    WSGIProcessGroup %{GLOBAL}
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptAlias / /var/www/html/databaseProject/databaseProject/wsgi.py

</VirtualHost>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...