Django Bad Request(400)在数字海洋Ubuntu 16.04服务器上运行Nginx和Gunicorn

时间:2017-03-26 05:10:51

标签: django nginx gunicorn digital-ocean

我有十几个数字海洋水滴设置使用相同的配置没有问题,但由于某种原因我无法加载这一个站点 - 访问我的服务器的IP地址时,我一直收到Bad Request (400)错误。该网站在localhost上工作正常。

此时我不确定此处包含的内容和数量,所以我已经包含了基础知识。

我在我的智慧结束..请帮助!

Nginx错误日志

2017/03/26 04:37:14 [error] 1626#1626: *129 readv() failed (104: Connection reset by peer) while reading upstream, client: 82.113.98.143, server: 138.197.70.81, request: "POST / HTTP/1.1", upstream: "http://unix:/home/rooster/corbett/corbett.sock:/", host: "138.197.70.81:80"
2017/03/26 04:41:51 [error] 1626#1626: *325 readv() failed (104: Connection reset by peer) while reading upstream, client: 50.118.145.87, server: 138.197.70.81, request: "POST / HTTP/1.1", upstream: "http://unix:/home/rooster/corbett/corbett.sock:/", host: "138.197.70.81"
2017/03/26 04:43:29 [error] 1626#1626: *409 readv() failed (104: Connection reset by peer) while reading upstream, client: 31.29.63.51, server: 138.197.70.81, request: "POST / HTTP/1.1", upstream: "http://unix:/home/rooster/corbett/corbett.sock:/", host: "138.197.70.81"
2017/03/26 04:46:45 [error] 1626#1626: *581 readv() failed (104: Connection reset by peer) while reading upstream, client: 124.160.153.143, server: 138.197.70.81, request: "POST / HTTP/1.1", upstream: "http://unix:/home/rooster/corbett/corbett.sock:/", host: "138.197.70.81"

简单网站文件

server {
    listen 80;
    server_name 138.197.70.81;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/redrooster/corbett;
    }

    location /media/  {
       root  /home/redrooster/corbett;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/redrooster/corbett/corbett.sock;
    }
}

Gunicorn服务档案

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=redrooster
Group=www-data
WorkingDirectory=/home/redrooster/corbett
ExecStart=/home/redrooster/corbett/venv/bin/gunicorn --workers 3 --bind unix:/home/redrooster/corbett/corbett.sock crgapp.wsgi:application

[Install]
WantedBy=multi-user.target

**更新3/26/17 - 这是我几年前完成的第一个Django网站之一,所以我知道这个设置文件已经搞砸了,但我将在不久的将来重建,所以现在只是想从Python无处不在的数字海洋 - 只是想到我提到:) **

base.py

from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse_lazy
import os
import raven

RAVEN_CONFIG = {
    'dsn': 'xxx',
    'release': raven.fetch_git_sha(os.path.dirname(os.pardir)),
}

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# SECRET KEY: keep the secret key used in production secret!
def get_env_variable(var_name):
    try:
        return os.environ[var_name]
    except KeyError:
        error_msg = "Set the %s environment variable" % var_name
        raise ImproperlyConfigured(error_msg)


SECRET_KEY = 'xxx'

DEFAULT_FROM_EMAIL = 'Corbett Restaurant Group <donotreply@xxx.com>'

# 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.sitemaps',
    'adminsortable2',
    'crispy_forms',
    'widget_tweaks',
    'compressor',
    'ckeditor',
    'allauth',
    'allauth.account',
    'taggit',
    'crgapp',
    'crgapp.listings',
    'crgapp.leases',
    'crgapp.press',
    'crgapp.apps.dashboard',
    'smart_selects',
    'raven.contrib.django.raven_compat',
)

MIDDLEWARE_CLASSES = (
    '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.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'crgapp.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
            os.path.join(BASE_DIR, 'listings/templates'),
            os.path.join(BASE_DIR, 'leases/templates'),
            os.path.join(BASE_DIR, 'press/templates'),
            os.path.join(BASE_DIR, 'apps/dashboard/templates'),
        ],
        '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.media',
                'django.template.context_processors.static',
            ],
        },
    },
]

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',

    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
)

WSGI_APPLICATION = 'crgapp.wsgi.application'

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Tijuana'

SITE_ID = 1

USE_I18N = True

USE_L10N = True

USE_TZ = False

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
)

# Static Files
STATIC_URL = '/static/'
STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

# Media Files
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

COMPRESS_ENABLED = True

# http://django-crispy-forms.readthedocs.org/en/latest/install.html#template-packs
CRISPY_TEMPLATE_PACK = 'bootstrap3'

# Allauth & Social Accounts

LOGIN_URL = reverse_lazy('account_login')
LOGOUT_URL = reverse_lazy('account_logout')
LOGIN_REDIRECT_URL = reverse_lazy('nda_create')
ACCOUNT_LOGOUT_REDIRECT_URL = reverse_lazy('account_login')
ACCOUNT_SIGNUP_FORM_CLASS = 'crgapp.apps.dashboard.forms.SignupForm'
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_UNIQUE_EMAIL = True
SOCIALACCOUNT_AUTO_SIGNUP = False

# EMAIL SETUP
EMAIL_BACKEND = "sgbackend.SendGridBackend"
SENDGRID_API_KEY = "xxx"

# Ckeditor
CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'Custom',
        'toolbar_Custom': [
            ["Format", "Bold", "Italic", "Underline", "Strike", "SpellChecker"],
            ['NumberedList', 'BulletedList', "Indent", "Outdent", 'JustifyLeft', 'JustifyCenter',
             'JustifyRight', 'JustifyBlock'],
            ["Image", "Table", "Link", "Unlink", "Anchor", "SectionLink", "Subscript", "Superscript"], ['Undo', 'Redo'], ["Source"],
            ["Maximize"]
        ],
        'autoParagraph': False,
        'allowedContent': True,
    }
}
CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
CKEDITOR_IMAGE_BACKEND = 'pillow'
CKEDITOR_UPLOAD_PATH = 'uploads/'

production.py

from __future__ import absolute_import, unicode_literals

from .base import *

DEBUG = False

# PREPEND_WWW = True

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'xxx',
        'USER': 'xxx',
        'PASSWORD': 'xxx',
        'HOST': 'localhost',
        'PORT': '',
    }
}

ALLOWED_HOSTS = ['corbettrestaurantgroup.com', 'www.corbettrestaurantgroup.com', '138.197.70.81']

Nginx访问日志

89.15.238.169 - - [26/Mar/2017:16:41:36 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
89.15.238.169 - - [26/Mar/2017:16:41:36 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
190.104.176.246 - - [26/Mar/2017:16:41:39 +0000] "POST / HTTP/1.1" 400 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
190.104.176.246 - - [26/Mar/2017:16:41:39 +0000] "POST / HTTP/1.1" 400 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
62.74.1.228 - - [26/Mar/2017:16:41:42 +0000] "\xAA\x133\xAC\xBE&\xCC\x18\xB4\x99\xC6\x8E\xCA\xC8\xAA\xF4\x95-\xF9\x1F\xF5;~\xD4\xDB\xC8\xF8\xE3\xE0\x0F\x8C\x90&\x9F\xBB\xD4\xF8\xD6J]\x7F_C|uC\xF0\xC7\x96\xC5\xC3\xC5\xFB\x02N\xCF-\x11L\xBC}\xEB\xCB\xE0\xA1\x94\xDF\xFB@\xF7\x10B\x9E\xC2\xEC\x7F6(\x14C\x81i\xA4\xD0\xC3\xB0\xC2c\xEETH\x0F\xFA\x89\xA3u$\xCE6\xF1\xBE\xEF\xDA\xF2\xD5\x94$\x84\xD1\x91B\x1F3\xD3\x15\x80\xEB\xE1\x0E\xA9i\x95\xB7\x84}\xA6\x0Eg\xD8f\xB3\xC9\xADk\xCCo\x5C\x7F\xDC\x1A\xC8`8u\x0B\xE8!\xC7\xD8,\xD5w\xDAd\x0B^!\x94xu\xB0f\xDB8\xE6\xF9(m\xEB\xE0A\x08,\x00\xAD>?\x9E\xBEz\x9B\x0E0\x09\x11\x8F\xF9d\xE7\xBC,wM\xAF\xD0HK\x0C\xEC" 400 182 "-" "-"
112.198.99.16 - - [26/Mar/2017:16:41:45 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
197.211.53.242 - - [26/Mar/2017:16:41:45 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
112.198.99.16 - - [26/Mar/2017:16:41:45 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
201.227.226.149 - - [26/Mar/2017:16:41:45 +0000] "POST / HTTP/1.1" 400 37 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
201.227.226.149 - - [26/Mar/2017:16:41:47 +0000] "POST / HTTP/1.1" 400 37 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
121.54.39.152 - - [26/Mar/2017:16:41:50 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
89.204.135.21 - - [26/Mar/2017:16:41:52 +0000] "POST / HTTP/1.1" 400 37 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
89.204.135.21 - - [26/Mar/2017:16:41:52 +0000] "POST / HTTP/1.1" 400 37 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
171.48.77.54 - - [26/Mar/2017:16:41:53 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
41.190.3.253 - - [26/Mar/2017:16:41:55 +0000] "POST /s/d/etisalat_ng#openModal/ HTTP/1.1" 400 182 "-" "-"
159.0.142.150 - - [26/Mar/2017:16:41:58 +0000] "POST / HTTP/1.1" 400 37 "-" "-"
190.104.131.11 - - [26/Mar/2017:16:42:02 +0000] "POST / HTTP/1.1" 400 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
190.104.131.11 - - [26/Mar/2017:16:42:04 +0000] "POST / HTTP/1.1" 400 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
197.156.95.108 - - [26/Mar/2017:16:42:07 +0000] "POST / HTTP/1.1" 400 37 "-" "-"
82.114.168.157 - - [26/Mar/2017:16:42:08 +0000] "POST / HTTP/1.1" 405 182 "-" "-"
94.203.156.69 - - [26/Mar/2017:16:42:08 +0000] "POST / HTTP/1.1" 405 182 "-" "-"
190.104.176.188 - - [26/Mar/2017:16:42:10 +0000] "POST / HTTP/1.1" 400 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
190.104.176.188 - - [26/Mar/2017:16:42:10 +0000] "POST / HTTP/1.1" 400 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
197.211.53.241 - - [26/Mar/2017:16:42:11 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
197.211.53.241 - - [26/Mar/2017:16:42:12 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
197.156.103.225 - - [26/Mar/2017:16:42:13 +0000] "POST / HTTP/1.1" 405 182 "-" "-"
203.87.252.161 - - [26/Mar/2017:16:42:15 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
203.87.252.161 - - [26/Mar/2017:16:42:15 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
197.211.53.242 - - [26/Mar/2017:16:42:15 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"
197.211.53.242 - - [26/Mar/2017:16:42:16 +0000] "POST / HTTP/1.1" 405 182 "-" "Apache-HttpClient/UNAVAILABLE (java 1.5)"

0 个答案:

没有答案