Django部署失败,远程系统

时间:2015-10-10 15:53:27

标签: django nginx port web-deployment gunicorn

我试图弄清楚如何在运行CentOS 7的虚拟服务器上发布我的Django支持的网页。我首先尝试使用gunicorn和nginx在我的笔记本电脑上本地运行没有调试模式的页面,但当我将它移动到服务器和nginx.conf内部的外部IP时,没有任何作用。我已经ping了IP地址并且运行成功,还使用telnet检查了端口(80)并且它已成功,因此无法阻止它。

下面我展示了我的nginx.confgunicorn.conf.pyapp/settings.py个文件。到目前为止,我只有一个服务器的IP,但我认为它应该工作,只要我有正确的设置。

nginx.conf

server {
    listen 80;
    server_name <server ip>;

    access_log /<project dir>/logs/nginx-access.log;
    error_log  /<project dir>/logs/nginx-error.log; 

    location / {
        proxy_pass http://127.0.0.1:9000;
    }

    location /static {
        root /<project dir>/static/;
        autoindex on;
        include /etc/nginx/mime.types;
    }
}

gunicorn.conf.py

bind = "127.0.0.1:9000"
errorlog = '/<project dir>/logs/gunicorn-error.log'
accesslog = '/<project dir>/logs/gunicorn-access.log'
loglevel = 'debug'
workers = 5  

settings.py

import os, djcelery
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = <secret>
DEBUG = False
ALLOWED_HOSTS = [<server ip>, '0.0.0.0', '127.0.0.1', 'localhost']

# Application definition
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.sites',
    'django.contrib.staticfiles',
    'interface',
    'kombu.transport.django',
    'app.tasks',
    'json',
    'django_nvd3',
    'djangobower',
    'allauth',
    'allauth.account',
)

MIDDLEWARE_CLASSES = (
    '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',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'app.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['interface'],
        '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.core.context_processors.request',
            ],
        },
    },
]

WSGI_APPLICATION = 'app.wsgi.application'

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)

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

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Europe/Berlin'
USE_I18N = True
USE_L10N = True
USE_TZ = True

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATICFILES_DIRS = ['interface', 'app']

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'djangobower.finders.BowerFinder',
)

BOWER_COMPONENTS_ROOT = BASE_DIR
BOWER_PATH = '/usr/local/bin/bower'

BOWER_INSTALLED_APPS = (
    'd3#3.3.13',
    'nvd3#1.7.1',
)

SITE_ID = 1

ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 7
ACCOUNT_UNIQUE_EMAIL=True
ACCOUNT_PASSWORD_MIN_LENGTH = 7

#EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = DEFAULT_FROM_EMAIL = <secret>
EMAIL_HOST_PASSWORD = <secret>

ACCOUNT_SIGNUP_FORM_CLASS = 'interface.forms.SignupForm'
TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, "app/interface/"),
)

1 个答案:

答案 0 :(得分:0)

您需要将端口设置为80,将server_name设置为实际的域名。