[英]502 Bad Gateway, Django, Nginx, Gunicorn, Postgresql, Virtualenv
我已經在這一個星期了。 我一直在嘗試在數字海洋上部署一個小測試應用程序,我已經遵循了許多這樣的教程: https : //www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-與-的Postgres-nginx的-和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 Bad Request。
我運行以下命令:
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中我重復了這個錯誤:
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文件:
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 / sites-available / blogger中的配置文件:
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:
blog.wsgi:application --bind 188.166.62.146:8001
/ opt / blogger / blog#gunicorn blog.wsgi:application --bind 127.0.0.1:8001
[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
[1]+ gunicorn blog.wsgi:application --bind 127.0.0.1:8001
首先,將您的nginx服務器名稱更改為您的IP地址。
然后將gunicorn綁定到127.0.0.1:8001。
據我所知,這筆交易是nginx,它會轉發從服務器名稱到proxy_pass變量的所有傳入請求。 然后向你指向proxy_pass的地方發出gunicorn回答請求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.