簡體   English   中英

DigitalOcean使用Nginx和Gunicorn將域添加到Django實例

[英]DigitalOcean add domain to django instance with nginx and gunicorn

我已經在digitalocean上安裝了一鍵安裝django並添加了一個域。 我還試圖在站點上線之前添加子域。 我已經如下編輯了nginx conf文件

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name beta.kazi-connect.com;

    keepalive_timeout 5;

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/django_project/django_project/media;
    }

    # your Django project's static files - amend as required
    location /static {
        alias /home/django/django_project/django_project/static;
    }

    # Proxy the static assests for the Django Admin panel
    location /static/admin {
       alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
    }

    location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_redirect off;
            proxy_buffering off;

            proxy_pass http://app_server;
    }

}

upstream app_server {
    server unix:/home/django/gunicorn.socket fail_timeout=0;
}

並重新啟動了nginx和gunicorn,但是當我訪問該子域時,出現了502錯誤的網關錯誤。

Nginx日志指出Gunicorn存在問題。

2017/01/24 16:24:19 [error] 6258#6258: *2 upstream prematurely closed connection while reading response header from upstream, client: 105.230.203.101, server: beta.kazi-connect.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "beta.kazi-connect.com"
2017/01/24 16:24:20 [error] 6258#6258: *2 upstream prematurely closed connection while reading response header from upstream, client: 105.230.203.101, server: beta.kazi-connect.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/favicon.ico", host: "beta.kazi-connect.com", referrer: "http://beta.kazi-connect.com/"
2017/01/24 16:24:22 [error] 6258#6258: *2 upstream prematurely closed connection while reading response header from upstream, client: 105.230.203.101, server: beta.kazi-connect.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "beta.kazi-connect.com"
2017/01/24 16:24:23 [error] 6258#6258: *2 upstream prematurely closed connection while reading response header from upstream, client: 105.230.203.101, server: beta.kazi-connect.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/favicon.ico", host: "beta.kazi-connect.com", referrer: "http://beta.kazi-connect.com/"
2017/01/24 16:25:00 [error] 6258#6258: *23 upstream prematurely closed connection while reading response header from upstream, client: 105.230.203.101, server: beta.kazi-connect.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "beta.kazi-connect.com"
2017/01/24 16:25:01 [error] 6258#6258: *23 upstream prematurely closed connection while reading response header from upstream, client: 105.230.203.101, server: beta.kazi-connect.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/favicon.ico", host: "beta.kazi-connect.com", referrer: "http://beta.kazi-connect.com/"

塞繆爾的回答是正確的。 問題是域名不包含在ALLOWED_HOSTS中。 在django_project / settings.py中,搜索以下代碼。

# Discover our IP address
ALLOWED_HOSTS = ip_addresses()

將您的域名添加到ALLOWED_HOSTS,例如

ALLOWED_HOSTS.extend(["xyz.com"])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM