使用django 2.0从管理面板中的css文件上出现错误403

时间:2018-09-05 20:05:54

标签: python django nginx collectstatic

我遇到以下问题,我的管理面板未加载CSS文件,您会看到类似的内容

this image

在控制台上显示以下错误消息:

[messages error] 2

,并在my files]上具有此“ user:group” 静态文件目录内容: static files]

最后是我的settings.py和nginx配置内容

Settings.py

    """
Django settings for oasiSystem project.

Generated by 'django-admin startproject' using Django 2.0.2.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os
from datetime import datetime

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


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!7p2^8bz736on1%%gcm)5^s21drrqz+$-=cj35*_ie((hvyl1-'

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

ALLOWED_HOSTS = ['159.89.150.67']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'reset_migrations',
    'apps.captura',
    'apps.cliente',
    'apps.cliente',
    'apps.cotizacion',
    'apps.empleado',
    'apps.reportes',
    'apps.sucursal',
    'apps.estado',
    'apps.pais',
    'apps.utils',
    'apps.usuario',
    'apps.kernel',
    'apps.sendMail',
]

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.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'oasiSystem.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
#        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'DIRS': [os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'templates/registration')],
        '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 = 'oasiSystem.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'oasis',
        'USER': 'root',
        'PASSWORD': 'neko1234',
        'HOST': 'localhost',
        'PORT': 3306,
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.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/2.0/topics/i18n/

LANGUAGE_CODE = 'es-mx'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATICFILES_DIR = [
                        os.path.join(BASE_DIR, 'static'),
                        '/root/Envs/.venv/lib/python3.5/site-packages/django/contrib/admin/static/admin',
                  ]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

ADMIN_MEDIA_PREFIX = '/static/admin'

MEDIA_ROOT = ['media']

PRIVATE_STORAGE_ROOT = (os.path.join(BASE_DIR, 'media'),)

# Configuracion del redireccionamiento del login (aun falta trabajarlo mas)
LOGIN_URL = 'login'
LOGIN_REDIRECT_URL = 'empleado'

nginx-config

server{
    listen 80;
    access_log /home/django/logs/access.log;
    error_log /home/django/logs/error.log;

    server_name apps.oasissorting.com;

    location / {
    proxy_pass http://127.0.0.1:8000;

    proxy_pass_header Server;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    }

    location /static {
#       alias /home/django/oasisystem3/static/;
#       alias /root/Envs/.venv/lib/python3.5/site-packages/django/contrib/admin/static/;
        alias /root/Envs/.venv/lib/python3.5/site-packages/django/contrib/admin/static/admin;
        expires modified +1w;
    }
    location /media {
        alias /home/django/oasisystem3/media/;
    }
    location /static/admin {
        alias /root/Envs/.venv/lib/python3.5/site-packages/django/contrib/admin/static/admin;
    }
}

Nginx error.log

2018/09/05 20:24:08 [error] 2783#2783: *9 open() "/root/Envs/.venv/lib/python3.5/site-packages/django/contrib/admin/static/admin/css/base.css" failed (13: Permission denied), client: 187.189.71.2, server: apps.oasissorting.com, request: "GET /static/admin/css/base.css HTTP/1.1", host: "159.89.150.67", referrer: "http://159.89.150.67/admin/"
2018/09/05 20:24:08 [error] 2783#2783: *9 open() "/root/Envs/.venv/lib/python3.5/site-packages/django/contrib/admin/static/admin/css/dashboard.css" failed (13: Permission denied), client: 187.189.71.2, server: apps.oasissorting.com, request: "GET /static/admin/css/dashboard.css HTTP/1.1", host: "159.89.150.67", referrer: "http://159.89.150.67/admin/"
2018/09/05 20:24:08 [error] 2783#2783: *11 open() "/root/Envs/.venv/lib/python3.5/site-packages/django/contrib/admin/static/admin/css/responsive.css" failed (13: Permission denied), client: 187.189.71.2, server: apps.oasissorting.com, request: "GET /static/admin/css/responsive.css HTTP/1.1", host: "159.89.150.67", referrer: "http://159.89.150.67/admin/"

在这种情况下我有什么错误?,感谢您的帮助<3

0 个答案:

没有答案