Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uWSGI nginx error : connect() failed (111: Connection refused) while connecting to upstream

Tags:

nginx

uwsgi

I'm experiencing 502 gateway errors when accessing my IP on nginx(http://52.xx.xx.xx/), the logs simply says this:

2015/09/18 13:03:37 [error] 32636#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: xx.xx.xx.xx, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8000", host: "xx.xx.xx.xx"

my nginx.conf file

# the upstream component nginx needs to connect to
upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 127.0.0.1:8000; # 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 xx.xx.xx.xx; # substitute your machine's IP address or FQDN
    charset     utf-8;

    access_log /home/ubuntu/test_django/nginx_access.log;
    error_log  /home/ubuntu/test_django/nginx_error.log;


    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
    alias /home/ubuntu/test_django/static/media/;  # your Django project's media files - amend as required
    }

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

    # Finally, send all non-media requests to the Django server.
    location / {
    uwsgi_pass  django;
    include  /home/ubuntu/test_django/uwsgi_params; # the uwsgi_params file you installed
    }
}

Is there anything wrong with nginx.conf file.....if i use default conf then it is working.

like image 582
FlyingHeem Avatar asked Sep 18 '15 13:09

FlyingHeem


1 Answers

I resolved it by changing the socket configuration in uwsgi.ini from socket = 127.0.0.1:3031, to socket = :3031. I was facing this issue when I ran nginx in one Docker container and uWSGI in another. If you are using command line to start uWSGI then do uwsgi --socket :3031.

Hope this helps someone stuck with the same issue, during deployment of a Django application using Docker.

like image 69
Vignesh Sk Avatar answered Nov 03 '22 20:11

Vignesh Sk