Heem
Heem

Reputation: 123

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

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.

Upvotes: 8

Views: 22621

Answers (5)

Vignesh Sk
Vignesh Sk

Reputation: 473

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.

Upvotes: 8

Óli Tómas
Óli Tómas

Reputation: 1

pip3 install uWSGI did the trick for me :D

Upvotes: -1

jaimeandrescatano
jaimeandrescatano

Reputation: 166

In my case with a debian server it worked moving:

include     /etc/nginx/uwsgi_params;

In the location tag in my nginx server config file, like this:

location /sistema {
    include     /etc/nginx/uwsgi_params;
    uwsgi_pass  unix://path/sistema.sock;
}

Also, check you have the following packages installed: uwsgi-plugin-python

Upvotes: -1

Bruce Li
Bruce Li

Reputation: 173

I ran into this issue when setting up the env by nginx + gunicorn and solve it by adding '*' to ALLOWED_HOSTS or your specific domain.

Upvotes: -1

Ankit Dhawan
Ankit Dhawan

Reputation: 51

change this address:

include  /home/ubuntu/test_django/uwsgi_params;

to

include     /etc/nginx/uwsgi_params;

Upvotes: -1

Related Questions