首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >502 Bad Gateway,Django,Nginx,Gunicorn,Postgresql,Virtualenv

502 Bad Gateway,Django,Nginx,Gunicorn,Postgresql,Virtualenv
EN

Stack Overflow用户
提问于 2015-02-20 12:32:26
回答 1查看 4.6K关注 0票数 0

我已经做了一个星期了。我一直试图在数字海洋上部署一个小测试应用程序,我遵循了许多教程,比如:https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn

我甚至尝试过单击安装教程:https://www.digitalocean.com/community/tutorials/how-to-use-the-django-one-click-install-image

昨晚我试了一次,我发现这是最近的一次:http://franklevering.me/blog/how-deploy-your-django-app-postgresql-nginx-and-gunicorn

当我去我的IP:http://188.166.62.146时,我得到了欢迎来到nginx!页面。当我去http://188.166.62.146:8001的时候,我收到了400个坏请求。

我运行以下命令:

代码语言:javascript
复制
gunicorn --log-file=- blog.wsgi:application

[2015-02-20 07:02:55 +0000] [6089] [INFO] Starting gunicorn 19.2.1
[2015-02-20 07:02:55 +0000] [6089] [INFO] Listening at: http://127.0.0.1:8000 (6089)
[2015-02-20 07:02:55 +0000] [6089] [INFO] Using worker: sync
[2015-02-20 07:02:55 +0000] [6094] [INFO] Booting worker with pid: 6094

在/var/log/nginx中,重复了这个错误:

代码语言:javascript
复制
2015/02/20 03:07:27 [error] 4755#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 95.128.91.3, server: 188.166.62.146, request: "GET /favicon.ico HTTP/1.1", u$$.1", upstream: "http://127.0.0.1:8001/favicon.ico", host: "188.166.62.146"

这是我的settings.py文件:

代码语言:javascript
复制
DEBUG = TEMPLATE_DEBUG = False


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

ALLOWED_HOSTS = []


INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'posts',
)

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',
)

ROOT_URLCONF = 'blog.urls'

WSGI_APPLICATION = 'blog.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'blog',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
    }
}
LANGUAGE_CODE = 'en-us'

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Nicosia'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_ROOT = '/opt/blogger/blog/static/'
STATIC_URL = '/static/'

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

以下是etc/nginx/site中的配置文件-可用/blogger:

代码语言:javascript
复制
server {
    server_name project.com;

    access_log off;

    location /static/ {
        alias /opt/blogger/blog/static/;
    }

    location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }
}

我使用当前的命令绑定gunicorn:

代码语言:javascript
复制
blog.wsgi:application --bind 188.166.62.146:8001

/opt/blogger/blog# gunicorn blog.wsgi:application --绑定127.0.0.1:8001

代码语言:javascript
复制
[2015-02-20 13:02:37 +0000] [7922] [INFO] Starting gunicorn 19.2.1
[2015-02-20 13:02:37 +0000] [7922] [INFO] Listening at: http://127.0.0.1:8001 (7922)
[2015-02-20 13:02:37 +0000] [7922] [INFO] Using worker: sync
[2015-02-20 13:02:37 +0000] [7927] [INFO] Booting worker with pid: 7927
^Z
[1]+  Stopped                 gunicorn blog.wsgi:application --bind 127.0.0.1:8001

/opt/blogger/blog# bg

代码语言:javascript
复制
[1]+ gunicorn blog.wsgi:application --bind 127.0.0.1:8001
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-20 15:23:17

首先,将nginx服务器名更改为IP地址。

然后将金刚角绑定到127.0.0.1:8001。

据我所知,nginx将转发从服务器名到proxy_pass变量的所有传入请求。然后对你指出的proxy_pass的位置做出回复请求。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28629112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档