1

Trying to get a basic Django app running on nginx using UWSGI. I keep getting a 502 error with the error in the subject line. I am doing all of this as root, which I know is bad practice, but I am just practicing. My config file is as follows (it's included in the nginx.conf file):

server { listen 80; server_name 104.131.133.149;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    root /home/root/headers;
}

location / {
    include         uwsgi_params;
    uwsgi_pass      127.0.0.1:8080;
}
}

And my uwsgi file is:

[uwsgi]
project = headers
base = /root

chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application

master = true
processes = 5

socket = 127.0.0.1:8080
chmod-socket = 666
vacuum = true

As far as I can tell I am passing all requests on port 80 (from nginx.conf) upstream to localhost, which is running on my VH, where uwsgi is listening on port 8080. I've tried this with a variety of permissions, including 777. If anyone can point out what I'm doing wrong please let me know.

HectorOfTroy407
  • 135
  • 1
  • 5

2 Answers2

0

I've faced something like that. I put the project to work doing like so:

upstream project {
    server project-backend:8000;
}

server {
    listen 80;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name project.alx.corp;

        ssl_certificate /etc/nginx/ssl/cert.crt;
        ssl_certificate_key /etc/nginx/ssl/cert.key;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers     HIGH:!aNULL:!MD5;

     location /static/ {
         alias /code/static/;
     }

    location / {
                proxy_pass http://project;
        include     /etc/nginx/uwsgi_params;
    }
}
[uwsgi]

base = /code/project
module = project.wsgi:application
logto = /code/logs/uwsgi.log
http-socket = 0.0.0.0:8000
master = 1
processes = 2
threads = 2
0

Ok so the issue was not starting up uwsgi with --socket 127.0.0.1:8080 option set! That was in my upstart script which now looks like:

start on runlevel [2345]
stop on runlevel [!2345]

setuid root
setgid root

exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites --socket 127.0.0.1:8080
HectorOfTroy407
  • 135
  • 1
  • 5