nginx uwsgi websockets 502 Bad Gateway upstream prematurely closed connection while reading response header from upstream

前端 未结 2 1884

I\'ve been banging my head on this issue for days now and have finally reached a brick wall.

I\'ve been trying to get my stack to run:

http://django-websock

2条回答
  •  一生所求
    2020-12-29 06:19

    I had same issue but it wasn't my NGINX configuration, it was my UWSGI processes causing timeout errors when I posted JSONs from client side to server. I had processes as 5, I changed it to 1 and it solved the issue. For my application, I only needed to have 1 process run at time since AWS didn't need to be overloaded with multiple processes.

    Here is the working UWSGI configuration ini file that solved the timeout issue and thus the 502 gateway issue.

    autoboot.ini

    #!/bin/bash
    
    [uwsgi]
    socket          = /tmp/app.sock
    
    master          = true
    
    chmod-socket    = 660
    module          = app.wsgi
    chdir           = home/app
    
    close-on-exec = true # Allow linux shell via uWSGI
    
    processes = 1
    threads = 2
    vacuum = true
    
    die-on-term = true
    

    Here's my nginx config too.

    nginx.conf

    # the upstream component nginx needs to connect to
    upstream django {
        server unix:///app/tmp/app.sock; # for a file socket
        # server 127.0.0.1:6000; # for a web port socket (we'll use this first)
    }
    
    # configuration of the server
    server {
        # the port your site will be served on
        listen      80;
    
        # the domain name it will serve for
        server_name XXX.XXX.XX.X #actual IP in here
        charset     utf-8;
    
        # max upload size
        client_max_body_size 75M;   # adjust to taste
    
        error_log /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log;
    
        # Finally, send all non-media requests to the Django server.
        location / {
            uwsgi_pass  django;
            include     uwsgi_params;
        }
    
        location /static {
            autoindex on;
            alias app/static; # your Django project's static files - amend as required
        }
    
        error_page 502 /502.html;
        location = /502.html {
            alias app/templates/502autoreload.html;
        }
    
        client_body_timeout 100s;
        uwsgi_read_timeout 500s;
        keepalive_timeout 300;
    }
    
    

提交回复
热议问题