Karesh A
Karesh A

Reputation: 1751

Django Nginx uWSGI 502 Bad Gateway always

I have been following the http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html

and went up to the

http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html#running-the-django-application-with-uwsgi-and-nginx

and started the uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=664 it is started but when i load my webpage on browser getting 502 Bad Gateway

Django version 1.10.2

error is

error] 25444#25444: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: mytest.com, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8001", host: "127.0.0.1:8000"

What could be the issue ?

# configuration of the server
server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name mytest.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

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

    # Django media
    location /media  {
        alias /home/karesh/tutorial/uwsgi-tutorial/mysite/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/karesh/tutorial/uwsgi-tutorial/mysite/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  unix:/home/karesh/tutorial/uwsgi-tutorial/mysite/mysite.sock;
        include     /home/karesh/tutorial/uwsgi-tutorial/mysite/uwsgi_params; # the uwsgi_params file you installed
    }
}

uwsgi_params file inside project directory

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;

Upvotes: 1

Views: 1781

Answers (1)

Andrii Rusanov
Andrii Rusanov

Reputation: 4606

A few things, that could help you: 1) Add user, that runs uWSGI, to nginx group 2) On CentOS with enabled SE the best way to put socket is a directory under /run 3) Set socket permissions to <your_user>:nginx(in other words - set permission for socket for your user and for nginx group.

These steps normally helps me to figure out with permissions error.

Upvotes: 0

Related Questions