Proxy_cache

demolitionman nginx-forum на forum.nginx.org
Ср Окт 11 05:55:51 UTC 2017


В общем решили на каждом Nginx держать свой кэш. и с помощью sync2 делать
синхронизацию этого кэша.
Если один nginx отвалится то LB перенаправит на другой. как бы все ок.
Тут у меня другая проблема появилась, уже моск весь сломал. не отдает
gunicorn стили.

 [error] 11431#0: *1 open() "/root/env/myproject/static/admin/css/login.css"
failed (13: Permission denied), client: 192.168.200.46, server:
10.230.40.190, request: "GET /static/admin/css/login.css HTTP/1.1", host:
"10.230.40.188", referrer: "http://10.230.40.188/admin/login/?next=/admin/"

blog.conf

server {
    listen 80;
    server_name 10.230.40.190;
    location / {
        proxy_pass http://10.230.40.190:8009;
        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;
        proxy_redirect off;
    }

location /static/ {

       autoindex off;
       root /root/env/myproject;
}

setting.py
import os

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

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'grj&8iul8=*5-!nbaf-86*+*3s!j%%pj(wdjg$x+jalbet на shm'

# 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',
]
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 = 'myproject.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 = 'myproject.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'gunicorn',
        'USER': 'gunicorn',
        'PASSWORD': 'gunicorn',
        'HOST': '10.230.40.194',
        'PORT': '5432',
    }
}

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

LANGUAGE_CODE = 'ru-ru'

TIME_ZONE = 'Asia/Almaty'

USE_I18N = True

USE_L10N = True
USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_ROOT = os.path.join(RESOURCE_DIR, 'static')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(RESOURCE_DIR, 'media')
MEDIA_URL = '/media/'
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

}

Когда захожу на сервер gunicorn напрямую http://10.230.40.190:8009/admin в
консоли ошибки
Not Found: /static/admin/css/login.css
Not Found: /static/admin/css/base.css
Не могу понять, где он пытается найти папку static? в корне что ли? Я везде
симлинки понаделал, результата 0

Posted at Nginx Forum: https://forum.nginx.org/read.php?21,122768,276803#msg-276803



Подробная информация о списке рассылки nginx-ru