繁体   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