无法让 Django Channels Daphne Nginx Supervisor 运行:502 错误网关

无法让 Django Channels Daphne Nginx Supervisor 运行:502 错误网关

我正在尝试回溯错误以找到我的域显示错误的核心问题502 bad Gateway。除了Django Channels 网站我已经完全遵循了。

我正在Django 2.1Digital Ocean Ubuntu 16.04 上使用 Python3+ 运行一个应用程序,使用Nginxsupervisor(它管理 daphne,因为需要 ASGI Django Channels)。

我没有使用 Gunicorn。

我就是无法让它工作,服务器端流程不是我的强项,所以如果有经验的人可以浏览一下并指出我可能没有意识到的任何主要问题,我会非常感激!

Nginx和均Supervisor正在运行。

nginx错误日志显示:

 connect() failed (111: Connection refused) while connecting to upstream, client: 86.xxx.xxx.xxx, server: myapp.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.myapp.com"

跑步sudo /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf

2019-02-27 16:39:55,627 CRIT Supervisor running as root (no user in config file)
2019-02-27 16:39:55,627 WARN Included extra file "/etc/supervisor/conf.d/myapp_asgi.conf" during parsing
2019-02-27 16:39:55,629 INFO Creating socket tcp://127.0.0.1:8000
2019-02-27 16:39:55,629 INFO Closing socket tcp://127.0.0.1:8000
Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.

我的 nginx 配置文件

upstream myapp {
    server 127.0.0.1:8000;
}

server {
    server_name myapp.com www.myapp.com;

    location = /favicon.ico { access_log off; log_not_found off; }

    location / {
        try_files $uri @proxy_to_app;
    }

    location /static/ {
        root /home/me/myapp/src/myapp;
    }

    location /media/  {
        root /home/me/myapp/src/myapp;
        include /etc/nginx/mime.types;
    }

    location @proxy_to_app {
        proxy_pass http://myapp;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/myapp.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/myapp.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}


server {
    if ($host = www.myapp.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = myapp.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name myapp.com www.myapp.com;
    return 404; # managed by Certbot
}

我的主管配置文件

[fcgi-program:asgi]
environment=PYTHONPATH=/usr/lib/python3.6/

# TCP socket used by Nginx backend upstream
socket=tcp://localhost:8000

# Directory where your site's project files are located
directory=/home/me/myapp/src/myapp

# Each process needs to have a separate socket file, so we use process_num
# Make sure to update "mysite.asgi" to match your project name
command=/home/me/Env/myapp/bin/daphne -u run/daphne/daphne%(process_nu$

# Number of processes to startup, roughly the number of CPUs you have
numprocs=4

# Give each process a unique name so they can be told apart
process_name=asgi%(process_num)d

# Automatically start and recover processes
autostart=true
autorestart=true

# Choose where you want your log to go
stdout_logfile=/home/me/daphne/logs/asgi.log
redirect_stderr=true

相关内容