Partage
  • Partager sur Facebook
  • Partager sur Twitter

déployer projet django nginx/gunicorn ubuntu

bad gateway

16 septembre 2017 à 19:29:52

bonjour, je suis le cours développez votre site web avec le framework django

j'essai de déployer avec la solution nginx/gunicorn mais j'ai un bad gateway, et je n'ai pas trouver par rapport aux logs

je travail dans un environement virtuel

j'ai un fichier test.sh dans mon projet qui contient les paramètre pour gunicorn

#!/bin/bash
set -e
LOGFILE=/var/log/gunicorn/mlorant.log
LOGDIR=$(dirname $LOGFILE)
LOGLEVEL=info   # info ou warning une fois l'installation OK
NUM_WORKERS=3    # Règle : (2 x $num_cores) + 1
# user/group to run as
USER=root
GROUP=root
cd /home/sandrine/Documents/Django/mon_projet/
source /home/sandrine/.virtualenvs/mon_projet/bin/activate  # Cette ligne ne sert que si vous utilisez virtualenv
test -d $LOGDIR || mkdir -p $LOGDIR
exec gunicorn mon_projet.wsgi:application -w $NUM_WORKERS \
  --user=$USER --group=$GROUP --log-level=$LOGLEVEL \
  --log-file=$LOGFILE 2>>$LOGFILE -b 127.0.0.1:8000

voici mon setting.py

"""
Django settings for mon_projet project.

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

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

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

import os

# 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/1.11/howto/deployment/checklist/

# 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
ALLOWED_HOSTS = ['localhost']

SITE_ID = 1

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.humanize',
    'social'
]

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',
    'django.middleware.locale.LocaleMiddleware',
]

ROOT_URLCONF = 'mon_projet.urls'

STATIC_ROOT = '/var/www/static_mon_python manage.py collectstatic --linkprojet/'

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',
		        'django.template.context_processors.i18n',
            ],
        },
    },
]

WSGI_APPLICATION = 'mon_projet.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# 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 = 'FR-fr'

TIME_ZONE = 'UTC'

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_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),   
    '/home/sandrine/Documents/Django/mon_projet/locale',

)

dans etc/nginx/site_availablee j'ai un fichier mon_projet

# Configuration du server

server {
    listen 8085;
    server_name localhost;
    charset     utf-8;

    access_log /var/log/nginx/mon_projet.access.log;
    error_log /var/log/nginx/mon_projet.error.log;

    # Fichiers media et statiques, délivrés par nginx directement
    location /media  {
        alias /home/sandrine/Documents/Django/mon_projet/media;
    }

    location /static {
        alias /home/sandrine/Documents/Django/mon_projet/static;
    }

    # Le reste va vers notre proxy uwsgi
    location / {
        include fastcgi_params;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        fastcgi_pass 127.0.0.1:8000;
    }
}

et voici mes log

error nginx

2017/09/16 19:13:27 [error] 16568#16568: *11 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:8000", host: "localhost:8085", referrer: "http://localhost:8085/admin"

access nginx

127.0.0.1 - - [16/Sep/2017:19:04:58 +0200] "GET /favicon.ico HTTP/1.1" 502 584 "http://localhost:8085/admin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36"

et j'ai un 

502 Bad Gateway


nginx/1.10.3 (Ubuntu)





  • Partager sur Facebook
  • Partager sur Twitter